Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Adjusting column width and height in QTableWidget
Forum Updated to NodeBB v4.3 + New Features

Adjusting column width and height in QTableWidget

Scheduled Pinned Locked Moved General and Desktop
qtablewidgetcolumn width ma
4 Posts 2 Posters 4.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    koahnig
    wrote on last edited by
    #1

    I have a QTableWidget with 2 columns. The first column is filled with a file name and the other column with some text through a QTextEdit.

    void StatisticDialog::addFilename(const QString &filename)
    {
        int pos = ui->twStatistic->rowCount();
        ui->twStatistic->setRowCount( pos + 1 );
        ui->twStatistic->setItem( pos, 0, new QTableWidgetItem ( filename ) );
        ui->twStatistic->setColumnWidth( 0, 150 );
    }
    
    void StatisticDialog::addResult(const QString &filename, const QString &res)
    {
        for ( int pos = 0; pos < ui->twStatistic->rowCount(); ++pos )
        {
            if ( ui->twStatistic->item( pos, 0 )->text() == filename )
            {
                QTextEdit *textEdit = new QTextEdit;
                textEdit->setText( res );
                textEdit->setReadOnly ( true );
                ui->twStatistic->setCellWidget( pos, 1, textEdit );
                ui->twStatistic->resizeColumnToContents( 1 );
                ui->twStatistic->resizeRowToContents( pos );
            }
        }
    }
    

    The second column width and row height remains in some sort of a standard sizes. I would like to the second column fitting the available space, but it doesn't. I guess the reason is the size of QTextEdit used.
    I had used already the QTextSize directly, but the results were even worse. This size seems even to vary with each QTextEdit being created. The result was that with every QTextEdit added, the column did shrink.

    Any suggestions?

    Vote the answer(s) that helped you to solve your issue(s)

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      If the second column is also the last you could try with QHeaderView's stretchLastSection property

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • K Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        Yes, it does. Obviously looked in the wrong part.

        Thanks for help.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          That one is a bit hidden for sure

          You're welcome !

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved