Results 1 to 5 of 5

Thread: Getting rid of whitespace in a QTableWidget

  1. #1
    Join Date
    Sep 2009
    Posts
    60
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Getting rid of whitespace in a QTableWidget

    I have a QTableWidget. The image attached is what it looks like. How do I make it so that when the dialog first starts up, I want it so that the dialog is only wide enough to show the two columns? I also want to make the QTableWidget shorter to get rid of the whitespace underneath the rows. Is there a setting or function I can use for that? This is what I have in the dialog init function. It is in python, but it is fairly equivalent to the C++ code.
    Qt Code:
    1. self.displayText = QTextEdit(self)
    2. self.labelTable = QTableWidget(1, 2, self)
    3.  
    4. self.acceptButton = QPushButton(self)
    5. self.acceptButton.setText("Accept")
    6.  
    7. self.cancelButton = QPushButton(self)
    8. self.cancelButton.setText("Cancel")
    9.  
    10. buttonGridLayout = QGridLayout()
    11. buttonGridLayout.addWidget(self.acceptButton, 0, 0, Qt.AlignLeft)
    12. buttonGridLayout.addWidget(self.cancelButton, 0, 1, Qt.AlignLeft)
    13.  
    14. gridLayout = QGridLayout()
    15. gridLayout.addWidget(self.labelTable, 0, 0)
    16. gridLayout.addWidget(self.displayText, 1, 0)
    17. gridLayout.addLayout(buttonGridLayout, 2, 0)
    18.  
    19. self.setLayout(gridLayout)
    20.  
    21. labels = QStringList()
    22. labels << "Type" << "Name"
    23.  
    24. self.labelTable.setHorizontalHeaderLabels(labels)
    To copy to clipboard, switch view to plain text mode 

    Also, How do I make the cells not editable?
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: Getting rid of whitespace in a QTableWidget

    Try to set the property "stretchLastSection" of the horizontalHeader of your tableview to true.
    It's nice to be important but it's more important to be nice.

  3. The following user says thank you to axeljaeger for this useful post:

    di_zou (11th December 2009)

  4. #3
    Join Date
    Sep 2009
    Posts
    60
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Getting rid of whitespace in a QTableWidget

    Yes that works. Thank you. How would I get rid of the white space at the bottom of the table? I don't want to use setStretchLastSection() because that makes the cells really tall. Resize(x, y) doesn't do anything. I would like to keep the widget as part of the layout so I guess what I really want to do is shrink the top cell of the gridlayout.

  5. #4
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Getting rid of whitespace in a QTableWidget

    So ... do you have a solution already?
    I tried ...
    Qt Code:
    1. vista->verticalHeader()->setStretchLastSection(true);
    To copy to clipboard, switch view to plain text mode 
    ... that would "solve" it if i knew how to align the text in a QTableView at the top.
    This way the last row could fill the remaining area

  6. #5
    Join Date
    Sep 2009
    Posts
    60
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Getting rid of whitespace in a QTableWidget

    I tried that already, and it causes the last row to be very tall. I don't want that. If you look at the screen shot I attached, I only have 1 row. I want the QTableWidget to end after that last row. I want the last row to be the same height as it is now and all the white space to be gone.

Similar Threads

  1. Replies: 7
    Last Post: 18th September 2009, 10:59
  2. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 23:29
  3. Select columns from a QTableWidget
    By toglez in forum Qt Programming
    Replies: 10
    Last Post: 7th October 2007, 15:15
  4. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 18:46
  5. Replies: 6
    Last Post: 5th March 2006, 21:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.