开发者

Scrolling area with PyQT on Maemo5

I'm not really accustomed to writing the UI in the code, so I need a few pointers. I'm trying to create a simple, horizontal scrolling dialog on my N900, but I can't figure out how to do this.

This is what I have so far:


    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(s开发者_如何转开发elf.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)


Pls, check if an example below would help you out, it should create a dialog with horizontal scroll area and buttons in it.

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_())

hope this helps, regards

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜