Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.9.3
-
None
-
Observed on Windows 10 with Visual Studio 2013 and Linux with GCC 6.2.0
Description
If you press the mouse on a widget (i.e. a QSlider) that is the child of a QStackedWidget, and without releasing the mouse, change the current widget of the QStackedWidget such that the widget under the mouse is no longer visible, mouse move events are still sent to the widget under the mouse.
This simple example demonstrates the problem.
QApplication app(argc, argv); QDialog d; QSlider * slider = new QSlider(&d); QLabel * label = new QLabel(&d); QStackedWidget * stack = new QStackedWidget(&d); QWidget * page1 = new QWidget(); QWidget * page2 = new QWidget(); stack->addWidget(page1); stack->addWidget(page2); QObject::connect(slider, &QSlider::valueChanged, label, [label, slider] (int value) { label->setText(QString::number(value)); }); QObject::connect(slider, &QSlider::sliderPressed, stack, [stack, page2] () { stack->setCurrentWidget(page2); }); QObject::connect(slider, &QSlider::sliderReleased, stack, [stack, page1] () { stack->setCurrentWidget(page1); }); QHBoxLayout * layout = new QHBoxLayout(page1); layout->addWidget(slider, 1); layout->addWidget(label, 0); QHBoxLayout * layout2 = new QHBoxLayout(&d); layout2->addWidget(stack, 1); d.exec();
In this example, QSlider::valueChanged is connected to a slot that updates a QLabel with the value, and QSlider::sliderPressed/Released will change the current widget of a QStackedWidget such that the slider's page is not current while the slider is pressed.
If you run this and drag the slider, after you release the mouse, the slider has moved and the label is showing the slider's value.
It feels wrong that mouse events are delivered to a widget that you can't see.
In my real-world (much more complex) example, moving the hidden slider leads to a crash because the the stacked widget in question is moving between two pages, the blank slate menu where no project is loaded, and the main project editing screen of the app. When you close the project and return to the blank slate, making any sort of edit would fail because the project is closed. Sure, we could add protection everywhere to deal with getting signals from widgets after we closed the project, but that means making a lot of changes, and remembering to do so for every new control added in future, whereas it is quite reasonable to think that hiding a widget would ungrab the mouse.