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. Set height of row of table
QtWS25 Last Chance

Set height of row of table

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt 5.5visual studioqtablewidgetqtableview
14 Posts 2 Posters 7.2k 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 SGaist
    26 Jul 2016, 22:00

    Hi and welcome to devnet,

    From the looks of it, you simply have an empty table. Add a row to it and you should see what you are looking for.

    N Offline
    N Offline
    nber
    wrote on 27 Jul 2016, 07:36 last edited by
    #3

    @SGaist thanks for your reply. Actually, this table is not empty, it has 1 row, as you can see in the result with Qt above. If I add one more row to it, the result with VS looks like this. Qt

    I tried to set the height of row, but it only works with QtCreator, with VS it is still the same. I am so headache with this problem. :(

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 27 Jul 2016, 10:41 last edited by
      #4

      Ok, got it.

      Here's your guilty line: ui->tableWidget->horizontalHeader()->setStretchLastSection(true);

      The horizontal header is the one for the rows. So you are asking that the last row takes as much vertical space as possible.

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

      N 1 Reply Last reply 27 Jul 2016, 14:02
      0
      • S SGaist
        27 Jul 2016, 10:41

        Ok, got it.

        Here's your guilty line: ui->tableWidget->horizontalHeader()->setStretchLastSection(true);

        The horizontal header is the one for the rows. So you are asking that the last row takes as much vertical space as possible.

        N Offline
        N Offline
        nber
        wrote on 27 Jul 2016, 14:02 last edited by
        #5

        Thanks @SGaist, actually in my opinion, you mixed the horizontal header with verical header already. I thinks this line makes the last column (not the row) to stretch to fit the width of the table. If I remove this line, the new table will look like this.

        Qt

        I am so confused because never ever had this problem :(. I still don't think there is problem with my code, because it works well with QtCreator, but in VS problem appears.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 31 Jul 2016, 17:44 last edited by
          #6

          Argle… Even after all these years I manage to get this one wrong…

          One thing that I haven't seen in your code, where do you set the row count in your widget ?

          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
          • N Offline
            N Offline
            nber
            wrote on 3 Aug 2016, 07:52 last edited by nber 8 Mar 2016, 08:07
            #7

            @SGaist : actually as I said, I did not do it in the code, I do it with QtDesigner, I set only 1 row. But I don't think it will create the difference between code and Qt Designer.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 3 Aug 2016, 10:38 last edited by
              #8

              Can you provide a minimal compilable example that reproduces that ?

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

              N 1 Reply Last reply 3 Aug 2016, 11:02
              0
              • S SGaist
                3 Aug 2016, 10:38

                Can you provide a minimal compilable example that reproduces that ?

                N Offline
                N Offline
                nber
                wrote on 3 Aug 2016, 11:02 last edited by nber 8 Mar 2016, 11:07
                #9

                @SGaist : I tested right on my code. If i add the line with RowCount in, in Qt Designer I dont set 1 row any more, the result still does not change. I still receive the table above.

                ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
                ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
                ui->tableWidget->setRowCount(1);
                ui->tableWidget->setColumnCount(5);
                ui->tableWidget->setHorizontalHeaderLabels(QStringList() << tr("First") << tr("Second") << tr("Third") << tr("Fourth") << tr("Fifth"));
                
                
                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 4 Aug 2016, 22:04 last edited by
                  #10

                  Which OS are you running ?

                  Testing with:

                      QApplication app(argc, argv);
                      QTableWidget tableWidget;
                      tableWidget.setSelectionBehavior(QAbstractItemView::SelectRows);
                      tableWidget.setSelectionMode(QAbstractItemView::SingleSelection);
                      tableWidget.setRowCount(1);
                      tableWidget.setColumnCount(5);
                      tableWidget.setHorizontalHeaderLabels(QStringList() << QObject::tr("First") <<  QObject::tr("Second") <<  QObject::tr("Third") <<  QObject::tr("Fourth") <<  QObject::tr("Fifth"));
                      tableWidget.show();
                      return app.exec();
                  

                  shows the table widget as you want it.

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

                  N 1 Reply Last reply 6 Aug 2016, 20:58
                  1
                  • S SGaist
                    4 Aug 2016, 22:04

                    Which OS are you running ?

                    Testing with:

                        QApplication app(argc, argv);
                        QTableWidget tableWidget;
                        tableWidget.setSelectionBehavior(QAbstractItemView::SelectRows);
                        tableWidget.setSelectionMode(QAbstractItemView::SingleSelection);
                        tableWidget.setRowCount(1);
                        tableWidget.setColumnCount(5);
                        tableWidget.setHorizontalHeaderLabels(QStringList() << QObject::tr("First") <<  QObject::tr("Second") <<  QObject::tr("Third") <<  QObject::tr("Fourth") <<  QObject::tr("Fifth"));
                        tableWidget.show();
                        return app.exec();
                    

                    shows the table widget as you want it.

                    N Offline
                    N Offline
                    nber
                    wrote on 6 Aug 2016, 20:58 last edited by nber 8 Jun 2016, 20:58
                    #11

                    @SGaist : I am using Windows 8.1, Visual Studio 2013, add-in Qt 5.5.1. If you use this code with just Qt Creator, it works. But i am coding with VS, the result is not good. If you can test it, please test with VS and shows me if you have the same result.

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 6 Aug 2016, 21:49 last edited by
                      #12

                      Sorry, I don't have that OS nor that version of Visual Studio at hand.

                      But I find it pretty surprising that the exact same code yields different result using the same compiler with only the IDE changing.

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

                      N 1 Reply Last reply 10 Aug 2016, 07:53
                      0
                      • S SGaist
                        6 Aug 2016, 21:49

                        Sorry, I don't have that OS nor that version of Visual Studio at hand.

                        But I find it pretty surprising that the exact same code yields different result using the same compiler with only the IDE changing.

                        N Offline
                        N Offline
                        nber
                        wrote on 10 Aug 2016, 07:53 last edited by
                        #13

                        @SGaist : until now I still dont know why. Maybe I have to create a model and using it...

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 10 Aug 2016, 08:58 last edited by
                          #14

                          QTableWidget already has an internal model otherwise it's a QTableView.

                          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
                          1

                          12/14

                          6 Aug 2016, 21:49

                          • Login

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