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. Qt Designer cannot set QTableWidget header column narrow
Forum Updated to NodeBB v4.3 + New Features

Qt Designer cannot set QTableWidget header column narrow

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 1.0k 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.
  • JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #1

    Using Qt Designer (4.8.1, Qt 5.12.2) on a QTableWidget I want to set all columns narrower than the default 50. I claim this does not work at run-time.

    From Designer:

    • horizontalHeaderDefaultSectionSize: 33
    • horizontalHeaderMinimumSectionSize: 30

    This shows up just as it should viewing the Designer ui file. So far so good.

    In the generated ui_....h file code generated shows:

    tableWidget_randDTable->horizontalHeader()->setDefaultSectionSize(33);
    tableWidget_randDTable->horizontalHeader()->setMinimumSectionSize(30);
    

    Again good.

    But at run-time columns are not narrow, I think they revert to the default of 50.

    To "workaround" I go into my constructor code and add (after the ui->setupUi(this);):

        int temp = ui->tableWidget_randDTable->horizontalHeader()->defaultSectionSize();
    
        ui->tableWidget_randDTable->horizontalHeader()->setDefaultSectionSize(33);
    

    Calling setDefaultSectionSize(33) makes it work. temp reports 50. Like it never got changed.

    What's going on?? I wonder whether in the Designer generated code, when it goes setDefaultSectionSize(33) it has not yet reduced minimumSectionSize from the default to 50 to below the new default, and so setting the default does not work?? But I cannot affect the order of the lines generated from the .ui.

    Would someone be kind enough to verify? Any better workaround, because this is not good?

    EDIT I just went into the ui_....h generated file. I manually swapped the lines to

    tableWidget_randDTable->horizontalHeader()->setMinimumSectionSize(30);
    tableWidget_randDTable->horizontalHeader()->setDefaultSectionSize(33);
    

    I managed to get it to recompile without regenerating from .ui. Sure enough, now it works!

    So.... provided you agree I now have a major problem, because the code as generated automatically is always to going to output in the order to stop narrowing default column width below 50 (before the line to reduce the minimum) is never to going to work, is it...?

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

      Sorry, did not saw it. 5.12.2 is too old - you need 5.12.3: https://codereview.qt-project.org/c/qt/qttools/+/255813

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

      JonBJ 1 Reply Last reply
      4
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi
        Win 10. Qt 5.14.1 . visual stud 2017

        For me, its shown at runtime as it looks in Designer
        Design
        alt text
        Runtime
        alt text

        1 Reply Last reply
        2
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #3

          I fixed this some time ago - what Qt version do you use? Or better - what Qt version does the uic executable use?

          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
          3
          • JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #4

            @mrjj, @Christian-Ehrlicher
            Thanks for replying. Your posts crossed with my edit....

            I just reposted my finding above with the version numbers of Creator & Qt. Which I'm restricted to, because I use what ships with Ubuntu 19.04....

            Using Qt Designer (4.8.1, Qt 5.12.2)

            and so uic 5.12.2.

            @Christian-Ehrlicher
            If this has been fixed let me know (which version). I'll mark your post as solving, and think about how I can workaround.

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

              Sorry, did not saw it. 5.12.2 is too old - you need 5.12.3: https://codereview.qt-project.org/c/qt/qttools/+/255813

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

              JonBJ 1 Reply Last reply
              4
              • Christian EhrlicherC Christian Ehrlicher

                Sorry, did not saw it. 5.12.2 is too old - you need 5.12.3: https://codereview.qt-project.org/c/qt/qttools/+/255813

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

                @Christian-Ehrlicher
                Thanks Christian. Unfortunate it's 5.12.2 that ships with Ubuntu 19.04, just my luck, lol!

                I'll have to manage, and I guess I'll move up to 20.04 if/when it arrives....

                mrjjM 1 Reply Last reply
                1
                • JonBJ JonB

                  @Christian-Ehrlicher
                  Thanks Christian. Unfortunate it's 5.12.2 that ships with Ubuntu 19.04, just my luck, lol!

                  I'll have to manage, and I guess I'll move up to 20.04 if/when it arrives....

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  If you are lucky 20.04 comes on April 23, 2020 :)

                  JonBJ 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    If you are lucky 20.04 comes on April 23, 2020 :)

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

                    @mrjj If it comes out at present.... That's another month of wide columns .... ;-)

                    mrjjM 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @mrjj If it comes out at present.... That's another month of wide columns .... ;-)

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #9

                      hehe in this virus infected world, i find wide columns to be of very little concern :)
                      But they are normally on time so you could be lucky :)

                      JonBJ 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        hehe in this virus infected world, i find wide columns to be of very little concern :)
                        But they are normally on time so you could be lucky :)

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

                        @mrjj You're right --- columns must now stand a minimum of 50 pixels apart for safety, lol ;-)

                        mrjjM 1 Reply Last reply
                        0
                        • JonBJ JonB

                          @mrjj You're right --- columns must now stand a minimum of 50 pixels apart for safety, lol ;-)

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #11

                          @JonB
                          Haha. Perfect answer if any user asks :)

                          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