I'm using Qt 5.2 and I have detect a special problematic behaviour by using QPushButton
s inside a QStackedWidget
which is child of a QDialog
.
Here's a simplified sample code (TestMainWindow
is a QMainWindow
and TestWidget
a QWidget
):
void TestMainWindow::onPushbutton()
{
QDialog d;
QVBoxLayout* mainLayout = new QVBoxLayout(&d);
this->stackedWidget = new QStackedWidget;
this->stackedWidget->addWidget( new TestWidget("Widget 1") );
this->stackedWidget->addWidget( new TestWidget("Widget 2") );
QPushButton* switcher = new QPushButton("switch Widget");
mainLayout->addWidget( this->stackedWidget );
mainLayout->addWidget( switcher );
connect( switcher, SIGNAL(clicked()), this, SLOT(switchWidget()) );
d.exec();
}
void TestMainWindow::switchWidget()
{
if( this->stackedWidget )
{
this->stackedWidget->setCurrentIndex( this->stackedWidget->currentIndex() == 0 ? 1 : 0 );
}
}
TestWidget::TestWidget(const QString &labelText, QWidget *parent)
: QWidget( parent )
{
QHBoxLayout* mainLayout = new QHBoxLayout( this );
mainLayout->addWidget( new QLabel(labelText) );
mainLayout->addWidget( new QPushButton("test") );
}
On Windows 7 you know the animation/effect, when you hover a button. This will happen in an endless loop (hover/not-hover) to the Button in the first Widget ("Widget 1") by starting the Dialog d
.
In my real application I noticed also that other events for this widget (e.g. focusing a line-edit) will only proceed when the QDialog
is moved.
So it also seems to me, that the first widget with a button in a QStackedWidget
runs in another event loop.
I captured this behaviour to the QPushButton
. When I don't have a QPushButton
in the widget, the focusing of the other widgets (e.g. line-edits) works fine as it should be. Only if there's a QPushButton
, the events are blocked until the parent Dialog is moved.
Have anybody ideas where this can came from and how to fix it?