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. QTableView row height
Forum Updated to NodeBB v4.3 + New Features

QTableView row height

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 5 Posters 1.6k 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by
    #1

    I want to shrink the row height for all rows in the table view as there's more vertical white space around the contents than I would like:

    ccc70026-f5b4-40da-85a9-517f7eb431c4-image.png

    something more like this is what I'm after:

    cf879017-d091-462e-9e61-8277c93312e0-image.png

    I rapidly found setRowHeight() but that just sets it for ONE row, not all rows.

    How should I do this please?
    Thanks, David

    JonBJ 1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by
      #2

      Hi had the same problem but I just did a loop for all the rows, e.g.

      int rowHeight = 28;
      for (int r = 0; (r < ui->myTableWidget->rowCount()); ++r)
              ui->myTableWidget->setRowHeight(r,rowHeight);
      
      1 Reply Last reply
      0
      • PerdrixP Perdrix

        I want to shrink the row height for all rows in the table view as there's more vertical white space around the contents than I would like:

        ccc70026-f5b4-40da-85a9-517f7eb431c4-image.png

        something more like this is what I'm after:

        cf879017-d091-462e-9e61-8277c93312e0-image.png

        I rapidly found setRowHeight() but that just sets it for ONE row, not all rows.

        How should I do this please?
        Thanks, David

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @Perdrix , @hskoglund
        To do this fixed for all rows --- so that e.g. it also applies whenever a new row is inserted --- you do it on QTableView->verticalHeader(). See https://stackoverflow.com/a/19304739 for example/discussion.

        1 Reply Last reply
        1
        • hskoglundH Offline
          hskoglundH Offline
          hskoglund
          wrote on last edited by
          #4

          Thanks @JonB good to know

          1 Reply Last reply
          0
          • PerdrixP Offline
            PerdrixP Offline
            Perdrix
            wrote on last edited by
            #5

            Except that my tableview doesn't have a vertical header... (or doesn't that matter)?

            D.

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

              Every tableview has a vertical and a horizontal header.

              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
              0
              • PerdrixP Offline
                PerdrixP Offline
                Perdrix
                wrote on last edited by Perdrix
                #7

                So is this right?

                //
                // Reduce the row height somewhat
                //
                QHeaderView* verticalHeader = pictureList->tableView->verticalHeader();
                double height = verticalHeader->defaultSectionSize();
                height *= 0.8;
                //verticalHeader->setSectionResizeMode(QHeaderView::Fixed);
                verticalHeader->setDefaultSectionSize(height);
                

                or do also need the setSectionResizeMode?

                Christian EhrlicherC M 2 Replies Last reply
                0
                • PerdrixP Perdrix

                  So is this right?

                  //
                  // Reduce the row height somewhat
                  //
                  QHeaderView* verticalHeader = pictureList->tableView->verticalHeader();
                  double height = verticalHeader->defaultSectionSize();
                  height *= 0.8;
                  //verticalHeader->setSectionResizeMode(QHeaderView::Fixed);
                  verticalHeader->setDefaultSectionSize(height);
                  

                  or do also need the setSectionResizeMode?

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Perdrix said in QTableView row height:

                  How do I find the default row height before any rows have been added?

                  Reading a documentation seems to be really hard for a lot of people... https://doc.qt.io/qt-6/qheaderview.html#defaultSectionSize-prop

                  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
                  1
                  • PerdrixP Perdrix

                    So is this right?

                    //
                    // Reduce the row height somewhat
                    //
                    QHeaderView* verticalHeader = pictureList->tableView->verticalHeader();
                    double height = verticalHeader->defaultSectionSize();
                    height *= 0.8;
                    //verticalHeader->setSectionResizeMode(QHeaderView::Fixed);
                    verticalHeader->setDefaultSectionSize(height);
                    

                    or do also need the setSectionResizeMode?

                    M Offline
                    M Offline
                    mpergand
                    wrote on last edited by
                    #9

                    @Perdrix
                    tableWidget->verticalHeader()->defaultSectionSize();
                    for me it's 30 pixels.

                    1 Reply Last reply
                    0
                    • PerdrixP Offline
                      PerdrixP Offline
                      Perdrix
                      wrote on last edited by Perdrix
                      #10

                      It's more a case of understanding WHERE you need to look - once you have the CORRECT part of the docs located, it's fine. Sometimes it's not always obvious.

                      PS I changed my post so it's now asking a different Q (that change crossed with your post).

                      D.

                      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