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. QTableWidget::resizeRowsToContents() doesn't work until user's manual action
Forum Updated to NodeBB v4.3 + New Features

QTableWidget::resizeRowsToContents() doesn't work until user's manual action

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.1k Views
  • 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.
  • S Offline
    S Offline
    sm.sabat
    wrote on last edited by
    #1

    I populate my QTableWidget with ComboBoxes:

    w = new QWidget;
    ui->tableWidget->setCellWidget(row, col, w);
    lay = new QHBoxLayout(w);
    w->setLayout(lay);
    box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    lay->addWidget(box, 0, Qt::AlignCenter);
    

    I call this function several times before I show QTableWidget to the user, and before that I do:

    ui->tableWidget->resizeColumnsToContents();
    ui->tableWidget->resizeRowsToContents();
    ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
    ui->tableWidget->repaint();
    

    QComboBoxes are visible in full and rows are a little wider than default (as to be expected). Now I call the functions again (with user looking) and the newly added row is stuck on default height (so it's too narrow for QComboBox to look good). After user clicks the vertical header, the row instantly snaps into the correct height fixing the visibility problem. What can I do to force QTableWidget to do this automatically?

    RatzzR 1 Reply Last reply
    1
    • S sm.sabat

      I populate my QTableWidget with ComboBoxes:

      w = new QWidget;
      ui->tableWidget->setCellWidget(row, col, w);
      lay = new QHBoxLayout(w);
      w->setLayout(lay);
      box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
      lay->addWidget(box, 0, Qt::AlignCenter);
      

      I call this function several times before I show QTableWidget to the user, and before that I do:

      ui->tableWidget->resizeColumnsToContents();
      ui->tableWidget->resizeRowsToContents();
      ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
      ui->tableWidget->repaint();
      

      QComboBoxes are visible in full and rows are a little wider than default (as to be expected). Now I call the functions again (with user looking) and the newly added row is stuck on default height (so it's too narrow for QComboBox to look good). After user clicks the vertical header, the row instantly snaps into the correct height fixing the visibility problem. What can I do to force QTableWidget to do this automatically?

      RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by
      #2

      @sm.sabat

      Can you try setResizeMode(QHeaderView::ResizeToContents)?

      --Alles ist gut.

      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Maybe this is related to https://bugreports.qt.io/browse/QTBUG-69563 ? But this only affects 5.11 and up.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        2

        • Login

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