Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.15.9
-
None
Description
I have a QTableWidget which is intended for multi selection of rows and contains a a QComboBox in one of the columns. When I have a stylesheet that modifies hover (e.g. QWidget:item:hover), selecting a few rows in the table and using the mouse to hover QComboBox causes the selected rows to change.
Not a fix, but just something I noticed: reverting the changes in https://github.com/qt/qtbase/commit/62f86b9b7ab3421c7a74c4c05a186847c76bfb28 (most specifically removing the line 'embeddedWidget(w)->setMouseTracking(true)' in src/widgets/styles/qstylesheetstyle.cpp) seems to address the issue as well.
To reproduce, below is a snippet of code that shows the issue.
- Run code with enableStylesheet set as true
- Use left mouse and shift to select multiple rows in the QTableWidget
- Now hover the mouse over one of the QComboBoxes in the 3rd column and notice the selection drops.
- If you were to set enableStylesheet to false and repeat steps 2-3, the issue doesn't happen
NOTE: I noticed this on a step up to 5.15.9 from 5.13.1 (5.13.1 works how I would expect and doesn't have this issue)
#include <QApplication> #include <QWidget> #include <QHBoxLayout> #include <QTableWidget> #include <QTableWidgetItem> #include <QHeaderView> #include <QComboBox> int main(int argc, char *argv[]) { QApplication app(argc, argv); // When enabled, hovering over QComboBox in QTableWidget causes selection to change bool enableStylesheet = true; if (enableStylesheet) { app.setStyleSheet("QWidget:item:hover { background-color: #FF0000; color: #000000; }"); } QWidget *window = new QWidget(); QHBoxLayout *layout = new QHBoxLayout(window); QTableWidget *tableWidget = new QTableWidget(); tableWidget->setColumnCount(3); tableWidget->setHorizontalHeaderLabels({ "Column 1", "Column 2", "Column 3" }); tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); tableWidget->setAlternatingRowColors(true); tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); tableWidget->horizontalHeader()->setStretchLastSection(true); for (int i = 0; i < 10; ++i) { tableWidget->insertRow(i); for (int j = 0; j < 2; ++j) { tableWidget->setItem(i, j, new QTableWidgetItem(QString("%1:%2").arg(i).arg(j))); } QComboBox *comboBox = new QComboBox(); comboBox->setEditable(false); comboBox->addItems({ "a", "b", "c" }); comboBox->setCurrentIndex(0); tableWidget->setCellWidget(i, 2, comboBox); } layout->addWidget(tableWidget); window->setGeometry(100, 100, 400, 300); window->show(); return app.exec(); }