Pietro
Pietro

Reputation: 13164

Qt: How to resize an image in a table?

This code correctly displays an image, and resizes it when the window is resized:

QLabel *imageLabel;
QTabWidget *imageTabWidget;
// new...
imageTabWidget->addTab(imageLabel, "Image");

I would like the same behaviour putting the image in a table (still inside the previous tab). However all I can get now is a fixed size image:

QTableWidget *innerTable = new QTableWidget;
innerTable->setRowCount(1);
innerTable->setColumnCount(1);
innerTable->setCellWidget(0, 0, imageLabel);
innerTable->resizeColumnsToContents();
innerTable->resizeRowsToContents();
imageTabWidget->addTab(innerTable, "Image");

Is it possible to have a resizeable table at all?
Thank you.

Upvotes: 0

Views: 192

Answers (1)

paulm
paulm

Reputation: 5882

You need to use layouts to get things to re-size how you'd like, see:

http://doc.qt.digia.com/qt/layout.html

Using the designer makes creating layouts much easier. (Create a widget in the designer then create an instance of it in code, then add to the tab widget).

Upvotes: 1

Related Questions