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: how to show vertical header and set its size policy
Forum Updated to NodeBB v4.3 + New Features

QTableWidget: how to show vertical header and set its size policy

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 3 Posters 8.4k 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.
  • Christian EhrlicherC Christian Ehrlicher

    Your code does not compile. This works fine for me:

    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        QTableWidget table;
        QStringList verHeaderList({"One", "Two", "Three"});
        table.setRowCount(verHeaderList.size());
        table.setColumnCount(5);
    
        table.setVerticalHeaderLabels(verHeaderList);
        table.verticalHeader()->setVisible(true);
        table.show();
        return app.exec();
    }
    
    
    B Offline
    B Offline
    Black Imp
    wrote on last edited by
    #3

    @Christian-Ehrlicher
    thank you I obviously extracted some lines from a complex code I can't report entirely.
    Even creating a simple table like that, after you fixing, the problem remains: no vertical header appears.

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

      As I said - it works fine for me. Which OS and Qt version do you use?

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

      B 2 Replies Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        As I said - it works fine for me. Which OS and Qt version do you use?

        B Offline
        B Offline
        Black Imp
        wrote on last edited by
        #5

        @Christian-Ehrlicher
        windows 10, qt 5.12.5 msvc 2017 64bit

        1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          As I said - it works fine for me. Which OS and Qt version do you use?

          B Offline
          B Offline
          Black Imp
          wrote on last edited by
          #6

          @Christian-Ehrlicher
          Ok I've compiled separately this example and it works fine.
          The actual one is created in a QMdiSubWindow. I'll check for some Size policy inherited

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Black Imp
            wrote on last edited by Black Imp
            #7
            TableSubWindow::TableSubWindow(QWidget * parent, Qt::WindowFlags flags):QMdiSubWindow(parent, flags)
            {
                
                QSize size = UISupport::getInstance().getScreenGeometry();
                
                setAcceptDrops(true);
                setWindowTitle("Untitled");
            
                this->setContextMenuPolicy(Qt::CustomContextMenu);
            
                QWidget *mMainWidget = new QWidget();
                mMainWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
                QHBoxLayout * mMainLayout = new QHBoxLayout();
                mMainWidget->setLayout(mMainLayout);
                mMainLayout->setSpacing(0);
                mMainLayout->setContentsMargins(0,0,0,0);
            
                setWidget(mMainWidget);
            
                QVBoxLayout * mLeftLayout = new QVBoxLayout();
                mLeftLayout->setContentsMargins(0,0,0,0);
                mLeftLayout->setSpacing(0);
               
                QVBoxLayout * mRightLayout = new QVBoxLayout();
                mRightLayout->setContentsMargins(0,0,0,0);
                mRightLayout->setSpacing(0);
            
                mMainLayout->addLayout(mLeftLayout);
                mMainLayout->addLayout(mRightLayout);
            
                mTable = new Table();
                
                mLeftLayout->addWidget(mTable);
                
                
                
                setFocus();
            
                
                setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
            
                
            
            }
            
            
            Table::Table():QTableWidget(nullptr)
            {
               QStringList verHeaderList({"One", "Two", "Three"});
                setRowCount(verHeaderList.size());
                setColumnCount(5);
            
                setVerticalHeaderLabels(verHeaderList);
                verticalHeader()->setVisible(true);
            }
            

            with Table being

            class Table : public QTableWidget
            {
               // ...
            }
            
            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #8

              Please provide a minimal, compilable example as I did if you want to prove that it's a Qt problem.

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

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

                Hi,

                Beside what @Christian-Ehrlicher requested, are you sure that you are not modifying your table widget in another part of the code ?

                I see you register it with something. That something might be changing your table widget by deleting its content.

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

                B 1 Reply Last reply
                0
                • SGaistS SGaist

                  Hi,

                  Beside what @Christian-Ehrlicher requested, are you sure that you are not modifying your table widget in another part of the code ?

                  I see you register it with something. That something might be changing your table widget by deleting its content.

                  B Offline
                  B Offline
                  Black Imp
                  wrote on last edited by
                  #10

                  @SGaist I' m trying to extract a minimal code from a huge application which is quite hard. That ragistration has nothing to do with UI, it's simply a way for receiving async data from net which is completely detached at the moment and I forgot to remove it.
                  The real table I should use is created and modified dynamically by reading file or a settings dialog so I replaced it with that minimal hardcoded table which doesn't work anyway. If hardcoded table worked I would be able myself to understand how to fix the rest.
                  It works only if I create the table in main as suggested in his example but not if I put it inside a qmdiwindow with layouts structures easily readable from my code

                  SGaistS 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    Please provide a minimal, compilable example as I did if you want to prove that it's a Qt problem.

                    B Offline
                    B Offline
                    Black Imp
                    wrote on last edited by Black Imp
                    #11

                    @Christian-Ehrlicher maybe you miss the point: I don't waste my time trying to prove qt has some issues; if it were up to me I'd have never even used qt for the professional application I'm developing but it was not my decision and from answers like yours I've received sometimes I'm getting more and more convinced my client made the wrong decision.
                    I'm just trying to understand why I can't make it work as it seems it should be. By the way now it's quite clear it depends either on qmdisubwindow or on my layouts structures and settings

                    1 Reply Last reply
                    0
                    • B Black Imp

                      @SGaist I' m trying to extract a minimal code from a huge application which is quite hard. That ragistration has nothing to do with UI, it's simply a way for receiving async data from net which is completely detached at the moment and I forgot to remove it.
                      The real table I should use is created and modified dynamically by reading file or a settings dialog so I replaced it with that minimal hardcoded table which doesn't work anyway. If hardcoded table worked I would be able myself to understand how to fix the rest.
                      It works only if I create the table in main as suggested in his example but not if I put it inside a qmdiwindow with layouts structures easily readable from my code

                      SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      @Black-Imp said in QTableWidget: how to show vertical header and set its size policy:

                      It works only if I create the table in main as suggested in his example but not if I put it inside a qmdiwindow with layouts structures easily readable from my code

                      In that case, please make it a complete example that we can build to check what is going on.

                      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
                      • B Offline
                        B Offline
                        Black Imp
                        wrote on last edited by
                        #13

                        It works.
                        Sorry there was a huge string with style sheet in main and a row sets the style of all QHeaderView. That caused my problem.

                        Thank you

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

                          @Black-Imp said in QTableWidget: how to show vertical header and set its size policy:

                          Sorry there was a huge string with style sheet in main and a row sets the style of all QHeaderView. That caused my problem.

                          That's the reason why I wanted you to create a minimal example.

                          Please mark the topic as solved then.

                          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

                          • Login

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