1

我有一个SingleTweetWidget要显示的推文。

如果我把它放入 aQScrollArea中,一切正常。

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)

QScrollArea 中的 SingleTweetWidget

但是,如果我把它放到一个对话框中,就会有一些额外的空间。

def setupUi(self, widget):
    super(NewpostWindow, self).setupUi(widget)
    tweet = SingleTweetWidget(self.client, self.tweet, self)
    self.verticalLayout.insertWidget(0, tweet)

QDialog 中的 SingleTweetWidget

请注意时间 ( 6s ago) 和蓝色分隔线之间的空格。

它来自哪里?我不知道。

对了,你可以从https://github.com/WeCase/WeCase/blob/dev-0.06/src/TweetListWidget.py获取 SingleTweetWidget 的源代码

4

1 回答 1

0

QDialog具有在小部件之间放置垂直空间的布局。这是因为默认的最小高度QDialog高于两个小部件的高度。您可以使用self->setMinimumHeight(int)andself->setMaximumHeight(int)和宽度变体 orself->setFixedSize(w,h)等​​...

您可以为每个小部件设置最大/最小宽度/高度。

阅读有关QLayoutQDialogQt 的内容并查看一些示例。Qt 有很好的文档。看

http://qt-project.org/doc/

http://qt-project.org/doc/qt-4.8/examples-layouts.html

http://qt-project.org/doc/qt-4.8/qwidget.html#setFixedSize

于 2013-06-01T18:17:49.380 回答