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 remove white space around QTableWidget?

How to remove white space around QTableWidget?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 4.9k 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.
  • AmoghA Offline
    AmoghA Offline
    Amogh
    wrote on last edited by
    #1

    ![Good Day,
    Am trying to create a table with certain number of rows and columns, I am able to create a table perfectly fine, and this QTableWidget is been put in the mainwidget with some other visual elements, whenever i maximize the mainwidget i am getting this extra space around the table.
    How to get rid of that extra space please help!!0_1511486033601_Capture21234.PNG

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      To expand to fill the white space

      tablewidget->horizontalHeader()->setStretchLastSection(true);
      tablewidget->verticalHeader()->setStretchLastSection(true);
      

      To prevent expansion into whitespace (but might require you to set a maximum size manually) tablewidget->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents)

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      2
      • AmoghA Offline
        AmoghA Offline
        Amogh
        wrote on last edited by Amogh
        #3

        I am sorry sir, It is not working ,the last row is still stretched vertically :(

        joeQJ VRoninV 2 Replies Last reply
        0
        • AmoghA Amogh

          I am sorry sir, It is not working ,the last row is still stretched vertically :(

          joeQJ Offline
          joeQJ Offline
          joeQ
          wrote on last edited by
          #4

          @Amogh Hi,friend. Welcome.

          Try below snippet again:

              QHeaderView* headerView = horizontalHeader();
              headerView->setSectionResizeMode(FirstColumn,         QHeaderView::Fixed);
              headerView->setSectionResizeMode(SecondColumn,    QHeaderView::ResizeToContents); 
              headerView->setSectionResizeMode(ThirdColumn,        QHeaderView::Stretch);
          

          Just do it!

          1 Reply Last reply
          1
          • AmoghA Amogh

            I am sorry sir, It is not working ,the last row is still stretched vertically :(

            VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            @Amogh said in How to remove white space around QTableWidget?:

            the last row is still stretched vertically

            Yes, that's what tablewidget->verticalHeader()->setStretchLastSection(true); does. remove that line if that's not the behaviour you want

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            0
            • AmoghA Offline
              AmoghA Offline
              Amogh
              wrote on last edited by Amogh
              #6

              @VRonin @joeQ thanks a lot guys ...! really helped me figure it out !! :)

              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