Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-114791

Stylesheet that modifies hover is causing selection to change

    XMLWordPrintable

Details

    • Windows

    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.

      1. Run code with enableStylesheet set as true
      2. Use left mouse and shift to select multiple rows in the QTableWidget
      3. Now hover the mouse over one of the QComboBoxes in the 3rd column and notice the selection drops.
      4. 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();
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            mcdongle Mike Baran
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes