2

我不太习惯在代码中编写 UI,所以我需要一些指针。我试图在我的 N900 上创建一个简单的水平滚动对话框,但我不知道如何做到这一点。

这是我到目前为止所拥有的:


    def __init__(self,parent = None):

        QDialog.__init__(self,parent)
        #if name == None:
        self.setWindowTitle('Testing scrolling')
        self.scrollArea = QScrollArea(self)
        self.scrollArea.setWidgetResizable(True)
        self.scrollArea.setMinimumSize(100,150)
        self.aWidget = QWidget(self.scrollArea)
        self.aWidget.setMinimumSize(20,200)
        self.aWidget.setSizePolicy( QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.scrollArea.setSizePolicy( QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.scrollArea.setWidget(self.aWidget)
        scroller = self.scrollArea.property("kineticScroller").toPyObject()
        scroller.setEnabled(True)

        _layout = QGridLayout(self.aWidget)
        _layout.setSpacing(60)
        _layout.setMargin(11)

        _layout.addWidget(QPushButton('Test0'),0,0)
        _layout.addWidget(QPushButton('Test1'),0,1)
        _layout.addWidget(QPushButton('Test2'),0,2)
        _layout.addWidget(QPushButton('Test3'),0,3)
        _layout.addWidget(QPushButton('Test4'),0,4)
        _layout.addWidget(QPushButton('Test5'),0,5)
        _layout.addWidget(QPushButton('Test6'),0,6)
4

1 回答 1

4

请检查下面的示例是否对您有所帮助,它应该创建一个带有水平滚动区域和按钮的对话框。

class MyDialog(QDialog):
    def __init__(self,parent = None):
        QDialog.__init__(self,parent)

        self.setWindowTitle('Testing scrolling')
        self.setGeometry(250, 200, 350, 400)

        widget = QWidget()
        widgetLayout = QHBoxLayout()
        for i in range(0, 25):
            button = QPushButton("test button {0}".format(i))
            widgetLayout.addWidget(button)           
        widget.setLayout(widgetLayout)

        scrollArea = QScrollArea()
        scrollArea.setWidget(widget)

        dialogLayout = QVBoxLayout()
        dialogLayout.addWidget(scrollArea)    
        self.setLayout(dialogLayout)

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    dlg = MyDialog()
    dlg.show()
    sys.exit(app.exec_())

希望这会有所帮助,问候

于 2010-09-06T02:19:58.040 回答