tags:

views:

18

answers:

1

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(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)
+1  A: 

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

serge_gubenko
Worked like a charm, thank you! -- Strangely enough, the `.format(i)` part didn't work. Isn't that a basic function of python?
skerit
yes, it's new for version 2.6. Details here http://docs.python.org/library/stdtypes.html look for str.format(*args, **kwargs)
serge_gubenko