PDA

View Full Version : Getting rid of whitespace in a QTableWidget



di_zou
8th December 2009, 15:51
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.


self.displayText = QTextEdit(self)
self.labelTable = QTableWidget(1, 2, self)

self.acceptButton = QPushButton(self)
self.acceptButton.setText("Accept")

self.cancelButton = QPushButton(self)
self.cancelButton.setText("Cancel")

buttonGridLayout = QGridLayout()
buttonGridLayout.addWidget(self.acceptButton, 0, 0, Qt.AlignLeft)
buttonGridLayout.addWidget(self.cancelButton, 0, 1, Qt.AlignLeft)

gridLayout = QGridLayout()
gridLayout.addWidget(self.labelTable, 0, 0)
gridLayout.addWidget(self.displayText, 1, 0)
gridLayout.addLayout(buttonGridLayout, 2, 0)

self.setLayout(gridLayout)

labels = QStringList()
labels << "Type" << "Name"

self.labelTable.setHorizontalHeaderLabels(labels)

Also, How do I make the cells not editable?

axeljaeger
9th December 2009, 08:11
Try to set the property "stretchLastSection" of the horizontalHeader of your tableview to true.

di_zou
9th December 2009, 14:35
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.

graciano
9th December 2009, 22:34
So ... do you have a solution already?
I tried ...

vista->verticalHeader()->setStretchLastSection(true);
... 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 ;)

di_zou
10th December 2009, 15:40
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.