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

Fixes table widget not resizing column width correctly.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.6.2
    • Widgets: Itemviews
    • None

    Description

       

      The below code will not resize correctly:
      A Pull Request has been send to gerrit:
      https://codereview.qt-project.org/c/qt/qtbase/+/549686

      #include <QApplication>
      #include <QTableWidget>
      #include <QHeaderView>
      
      class Colorfull : public QWidget {
      public:
          Colorfull(const QSize& size, QWidget *parent= nullptr) : QWidget(parent) {    
              setStyleSheet("background-color:red;");
              setFixedSize(size);
          }
      };
      
      int main(int argc, char **argv)
      {
       QApplication app (argc, argv);
      
       QTableWidget table;
      
       table.setGeometry(0,0,400,400);
      
       table.setColumnCount(2);
       table.setRowCount(2);
       table.setHorizontalHeaderLabels({"First", "Second"});
      
       
       table.horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
       table.horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
       table.verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
          
       // Not Working
       table.setCellWidget(0, 0, new Colorfull(QSize(200,100)));   
       table.setCellWidget(1, 0, new Colorfull(QSize(100,100)));   
      
       // Working (Largest Widget Last)
      //  table.setCellWidget(0, 0, new Colorfull(QSize(100,100)));   
      //  table.setCellWidget(1, 0, new Colorfull(QSize(200,100)));   
      
       
       table.setItem(0, 1, new QTableWidgetItem("Some text"));
       table.setItem(1, 1, new QTableWidgetItem("Some more text"));
      
       table.show();
      
       return app.exec();
      }
      

      Attachments

        For Gerrit Dashboard: QTBUG-123534
        # Subject Branch Project Status CR V

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            lasse Lasse Wallentin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There is 1 open Gerrit change