I have a SingleTweetWidget
to display a tweet.
If I put it into a QScrollArea
, everything is working fine.
class TweetListWidget(QtGui.QWidget):
def __init__(self, client=None, parent=None):
super(TweetListWidget, self).__init__(parent)
self.setupUi()
def setupUi(self):
self.layout = QtGui.QVBoxLayout(self)
self.setLayout(self.layout)
def setModel(self, model):
self.model = model
self.model.rowsInserted.connect(self._rowsInserted)
def _rowsInserted(self, parent, start, end):
for index in range(start, end + 1):
item = self.model.get_item(index)
widget = SingleTweetWidget(self.client, item)
self.layout.insertWidget(index, widget)
But, if I put it into a dialog, there will be some extra space.
def setupUi(self, widget):
super(NewpostWindow, self).setupUi(widget)
tweet = SingleTweetWidget(self.client, self.tweet, self)
self.verticalLayout.insertWidget(0, tweet)
Please notice the space between the time (6s ago
) and the blue separator line.
Where is it come from? I have no idea with it.
By the way, you can get the source code of SingleTweetWidget from https://github.com/WeCase/WeCase/blob/dev-0.06/src/TweetListWidget.py
QDialog
has a layout which put a vertical space between widgets. It's because the default minimum height of QDialog
is higher than the height of the two widgets. You can use self->setMinimumHeight(int)
and self->setMaximumHeight(int)
and the width variants or self->setFixedSize(w,h)
, etc...
You can set max/min width/height with every widget.
Read something about QLayout
, QDialog
and the Qt and see some examples. Qt have very good documentation. See