[Interest] Window flicker when layout's size constraint is Fixed

Adam Light aclight at gmail.com
Thu Feb 2 19:25:26 CET 2012


Hi

I have a dialog in which many of the widgets are normally hidden but
are made visible when the user checks one of the radio buttons.
Basically, it's a Show more/Show less situation.

I want the size of the dialog to change depending on the visible
widgets, so I have set the layout used in the dialog to have
QLayout::SetFixedSize as it's size constraint.

In my slot that responds to the radio button clicking, I
enable/disable the various widgets as appropriate. I have noticed that
the dialog is resized multiple times as the widgets are made visible,
and this resizing is pretty easy to see and I don't like the effect. I
have tried calling setUpdatesEnabled(false) before I hide/reveal the
widgets, but the size of the dialog still changes several times though
the contents of the window aren't fully painted until updates are
enabled again so the window is drawn with garbage in it until it is
fully updated.

My goal is to have the dialog resize itself from one size to the final
size without the intermediate state(s) of the dialog being visible to
the user.

I am not sure if what I am seeing is a bug or not.

I have attached a .zip file which contains a simple compilable example
and very short Quicktime movies that show the beginning, intermediate,
and end states of the dialog that I captured when I checked the box in
the dialog.

I am using Qt 4.8.0 on Macintosh 10.6.8.

Here is the basic idea of the code contained in the attached .zip file:

class Dialog : public QDialog
{
	Q_OBJECT

public:
	explicit Dialog(QWidget *parent = 0) :
		QDialog(parent),
		checkBox(new QCheckBox("Show combo boxes", this)),
		comboBox(new QComboBox(this)),
		// initialize comboBox1-comboBox6
	{
		comboBox->addItem("aaa");
		// do the same for comboBox1-comboBox6 but make each item longer in length.
		checkBox->setChecked(true);

		QVBoxLayout* theLayout = new QVBoxLayout();
		theLayout->addWidget(comboBox);
		// do the same for comboBox1-comboBox6
		theLayout->addWidget(checkBox);
		theLayout->setSizeConstraint(QLayout::SetFixedSize);
		setLayout(theLayout);

		connect(checkBox, SIGNAL(toggled(bool)), this,
SLOT(on_checkBox_toggled(bool)));
	}

public slots:
	void on_checkBox_toggled(bool isChecked) {
		//setUpdatesEnabled(false);
		comboBox->setVisible(isChecked);
		// do the same for comboBox1-comboBox6
		//setUpdatesEnabled(true);
	}

private:
	// member widgets are here
};

Thanks for any help
Adam
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LayoutFixedSizeFlicker.zip
Type: application/zip
Size: 41991 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120202/28cd56e5/attachment.zip>


More information about the Interest mailing list