Ok, here's an example dummy widget that changes its size hint periodically:
{
public:
setStyleSheet("background: red"); // just to make it easier to see
startTimer(2000);
}
QSize sizeHint
() const { return sh;
} // notice "const"
protected:
if (sh.width() > 640)
updateGeometry(); // inform that the size hint has changed
}
private:
};
class Widget : public QWidget
{
public:
Widget(QWidget* parent = 0) : QWidget(parent), sh(320, 240) {
setStyleSheet("background: red"); // just to make it easier to see
startTimer(2000);
}
QSize sizeHint() const { return sh; } // notice "const"
protected:
void timerEvent(QTimerEvent* /*event*/) {
sh += QSize(40, 30);
if (sh.width() > 640)
sh = QSize(320, 240);
updateGeometry(); // inform that the size hint has changed
}
private:
QSize sh;
};
To copy to clipboard, switch view to plain text mode
Now, a dummy dialog that contains the above widget and a dialog button box:
int main(int argc, char* argv[])
{
layout
->setSizeConstraint
(QLayout::SetFixedSize);
// make the layout follow size hint layout->addWidget(new Widget);
dialog.setLayout(layout);
return dialog.exec();
}
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QDialog dialog;
QVBoxLayout* layout = new QVBoxLayout(&dialog);
layout->setSizeConstraint(QLayout::SetFixedSize); // make the layout follow size hint
layout->addWidget(new Widget);
layout->addWidget(new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel));
dialog.setLayout(layout);
return dialog.exec();
}
To copy to clipboard, switch view to plain text mode
This makes the whole dialog follow the size hint of the "red widget". Is this what you wanted?
Bookmarks