Setting min-width/max-width in stylesheet (.qss) does not work after setting layout size constraint of QDialog to QLayout::SetFixedSize
-
Two requirements for dialog:
- Want the dialog can resize to suitable size when any child widget changes size, so I set layout size constraint of dialog to QLayout::SetFixedSize.
- Want the width of the dialog can be customized by min-width/max-width to fixed value in stylesheet.
Issue:
min-width/max-width in stylesheet (.qss) does not work.Here is the code:
#include <qlayout.h> MyDialog::MyDialog(QWidget *parent) : QDialog(parent), ui(new Ui::MyDialog) { ui->setupUi(this); layout()->setSizeConstraint(QLayout::SetFixedSize); setStyleSheet("QDialog { min-width: 800px; max-width: 800px }"); // just a simple example, actually I want to customize in .qss file. }
Questions:
- Is it correct behavior that width can not be customized after setting size constraint to QLayout::SetFixedSize?
- How can I achieve the requirements?
-
@xiazeyi said:
Want the dialog can resize to suitable size when any child widget changes size, so I set layout size constraint of dialog to QLayout::SetFixedSize.
SetFixedSize sets, well, a fixed size. It means it is set to the size hint value and can't be changed anymore by anything. So in your case this is definitely not what you want.
Leave the size constraint at default and just specify the min and max values in the stylesheet.
-
How do you change the size of the children frames?
-
By making some widgets in QFrame visible/invisible when the user does some interaction on dialog.
Currently, I can set the direct children to fixed width instead of the dialog after setting size constraint of dialog to QLayout::SetFixedSize, then everything is ok.