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. How to resize vertical header in QTableWidget
QtWS25 Last Chance

How to resize vertical header in QTableWidget

Scheduled Pinned Locked Moved General and Desktop
13 Posts 4 Posters 8.0k 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.
  • T Offline
    T Offline
    technovelist
    wrote on last edited by
    #1

    I cannot figure out how to set the vertical header size for a QTableWidget. I have tried using resizeSection, but that doesn't seem to do anything other than wiping out the text I put in the vertical header. I have done a search here to no avail. Does anyone have an example of how to do this?

    Thanks.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      killerman
      wrote on last edited by killerman
      #2

      Is that what you want ?

      tableView->verticalHeader()->setDefaultSectionSize(YourValue)
      
      1 Reply Last reply
      0
      • T Offline
        T Offline
        technovelist
        wrote on last edited by technovelist
        #3

        I believe I have tried that to no avail, but I'll try it again and report back. Thanks.
        No, that seems to have no effect, but I don't know what "tableView" signifies exactly.
        Here's my code:

        QTableWidget *InsurancePremiumTable;
        ...
        ui->InsurancePremiumTable->setColumnCount(MaxYearsToModel);
        m_InsurancePremiumRowNames.append("Ins. Premium");
        ui->InsurancePremiumTable->setVerticalHeaderLabels(m_InsurancePremiumRowNames);
        ui->InsurancePremiumTable->verticalHeader()->setDefaultSectionSize(500);
        for (int row = 0; row < ui->InsurancePremiumTable->rowCount(); ++row)
        for (int column = 0; column < ui->InsurancePremiumTable->columnCount(); ++column)
        {
        QTableWidgetItem *newItem = new QTableWidgetItem("");
        ui->InsurancePremiumTable->setItem(row, column, newItem);
        }

        Can you see what I'm doing wrong? 500 isn't the actual size that I want, just a size that should show me that it's doing something.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alex_malyu
          wrote on last edited by
          #4

          try ui->InsurancePremiumTable->verticalHeader()- setSizeHint( QSize (500,500 ) );

          1 Reply Last reply
          0
          • T Offline
            T Offline
            technovelist
            wrote on last edited by
            #5

            No, that doesn't compile.
            1>mainwindow.cpp(737): error C3861: 'setSizeHint': identifier not found

            1 Reply Last reply
            0
            • A Offline
              A Offline
              alex_malyu
              wrote on last edited by alex_malyu
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • K Offline
                K Offline
                killerman
                wrote on last edited by killerman
                #7

                Try this:

                ui->InsurancePremiumTable->verticalHeader->setResizeMode(QHeaderView::Fixed);
                ui->InsurancePremiumTable->verticalHeader->setDefaultSectionSize( 500 );
                

                Or:

                ui->InsurancePremiumTable->verticalHeader->setResizeMode(QHeaderView::Fixed);
                ui->InsurancePremiumTable->verticalHeader()->resize( 500, 500 );
                

                If it doesn't help try changing size for a single row:

                ui->InsurancePremiumTable->setRowHeight( rowNumber, rowHeight );
                
                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  technovelist
                  wrote on last edited by technovelist
                  #8

                  This doesn't compile:
                  ui->InsurancePremiumTable->verticalHeader()->setResizeMode(QHeaderView::Fixed);

                  I get this error:
                  mainwindow.cpp(736): error C2039: 'setResizeMode' : is not a member of 'QHeaderView'

                  and if I write it as you did,
                  ui->InsurancePremiumTable->verticalHeader->setResizeMode(QHeaderView::Fixed);

                  then I get a different error:
                  1>mainwindow.cpp(736): error C2227: left of '->setResizeMode' must point to class/struct/union/generic type

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

                    Hi,

                    You are missing a #include <QHeaderView> in mainwindow.cpp file

                    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
                    • T Offline
                      T Offline
                      technovelist
                      wrote on last edited by
                      #10

                      Nope, that doesn't help; I get the same error:
                      1>mainwindow.cpp(745): error C2039: 'setResizeMode' : is not a member of 'QHeaderView'

                      Any other suggestions?

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

                        Because it's an obsolete function, see here for the replacement

                        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
                        • T Offline
                          T Offline
                          technovelist
                          wrote on last edited by
                          #12

                          That compiles okay but doesn't do anything visible other than wiping out my label

                          Here's my code:

                          ui->InsurancePremiumTable->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
                          ui->InsurancePremiumTable->verticalHeader()->resizeSection(0, 500);
                          m_InsurancePremiumRowNames.append("Ins.    Premium");
                          ui->InsurancePremiumTable->setVerticalHeaderLabels(m_InsurancePremiumRowNames);
                          for (int row = 0; row < ui->InsurancePremiumTable->rowCount(); ++row)
                          	for (int column = 0; column < ui->InsurancePremiumTable->columnCount(); ++column)
                          	{
                          		QTableWidgetItem *newItem = new QTableWidgetItem("");
                          		ui->InsurancePremiumTable->setItem(row, column, newItem);
                          	}
                          
                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            Your header width gets pretty big, isn't 500pixel a bit wide ?

                            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