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

Qt stylesheet issue with QTableView::item and cellWidget

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.15.2
    • Widgets: Style Sheets
    • None
    • Windows

    Description

      I've recently upgraded from Qt 5.6.3 to Qt 5.15.2 and started noticing the following issue. I have a QTableWidget which has a bunch of QComboBoxes as cell widgets. The application uses the following stylesheet:

      QComboBox:hover{background: yellow;}
      QTableView::item:hover{color: red;} 

      Now when showing the table and hovering over a QComboBox on the last visible row, the table starts auto-scrolling down, as shown in the attachment. This doesn't happen if I hover over a normal QTableWidgetItem on the last visible row as shown on the image.

      If I remove either of the hover keyword from the stylesheet, then things work fine but they style is lost. My guess is that there is a conflict between QTableView::item and QComboBox when it's used as a cell widget so I've tried being more explicit about which QComboBoxes the stylesheet should apply to by using

      QTableView QComboBox:hover{background: yellow;}
      QTableView::item:hover{color: red;} 

      but that didn't help either. I can confirm this issue didn't exist with Qt 5.6.3.

       

      Sample code for reproducing:

       

      #include <QTableWidget>
      #include <QComboBox>
      #include <QApplication>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          qApp->setStyleSheet(
                      "QComboBox{background: yellow;}"
                      "QTableView::item:hover{color: red;}"
                              );
      
          auto rows = 100;
          auto cols = 5;
          auto table = new QTableWidget(rows, cols);
      
          for(auto i = 0; i != rows; ++i)
          {
              for(auto j = 0; j != cols; ++j)
              {
                  if(j == 0)
                  {
                      auto item = new QTableWidgetItem("hello");
                      table->setItem(i, j, item);
                  }
                  else
                  {
                      auto cb = new QComboBox();
                      cb->addItems(QStringList() << "Item1" << "Item2");
                      table->setCellWidget(i, j, cb);
                  }
              }
          }
      
          table->setMinimumSize(800,600);
          table->show();
          return a.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
            gserm Georgios Sermaidis
            Votes:
            4 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes