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

How to resize vertical header in QTableWidget

Scheduled Pinned Locked Moved General and Desktop
13 Posts 4 Posters 8.0k Views 3 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.
  • T Offline
    T Offline
    technovelist
    wrote on 1 May 2015, 03:50 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 1 May 2015, 10:19 last edited by killerman 5 Jan 2015, 10:22
      #2

      Is that what you want ?

      tableView->verticalHeader()->setDefaultSectionSize(YourValue)
      
      1 Reply Last reply
      0
      • T Offline
        T Offline
        technovelist
        wrote on 1 May 2015, 23:37 last edited by technovelist 5 Jan 2015, 23:42
        #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 2 May 2015, 00:11 last edited by
          #4

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

          1 Reply Last reply
          0
          • T Offline
            T Offline
            technovelist
            wrote on 2 May 2015, 00:34 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 2 May 2015, 01:33 last edited by alex_malyu 5 Feb 2015, 01:55
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • K Offline
                K Offline
                killerman
                wrote on 2 May 2015, 07:17 last edited by killerman 5 Feb 2015, 07:22
                #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 2 May 2015, 15:25 last edited by technovelist 5 Feb 2015, 15:28
                  #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
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 2 May 2015, 19:24 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 3 May 2015, 00:00 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
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 3 May 2015, 00:31 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 3 May 2015, 15:19 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
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 3 May 2015, 21:41 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

                            9/13

                            2 May 2015, 19:24

                            • Login

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