PyQt QScrollView/QGridLayout question

Samir Grover samirg at lorentzsolution.com
Fri Jul 11 18:57:14 EDT 2008


folks, 

I am trying put some user input fields into a scrollable (QScrollView)
window. So,
I placed a QLabel at 0,0 and QLineEdit at 0,1, next to QLabel. 

Somehow, results are not what I am expecting.It is placing QLineEdit
below QLabel.
I am not using designer for this. Please, notice that I convert vbox's
box layout into
grid layout, so that, I can place QLabel at 0,0 and QLineEdit at 0,1.
But it does not
do that.  any advice on correcting this piece of code will be helpfull.
regards,

here is how this code looks like:

-----
import sys, qt
from qt import *


class MyDialog(QDialog):
    def __init__(self,parent = None,name = None,modal = 0,fl = 0):
        QDialog.__init__(self,parent,name,modal,fl)

        if not name:
            self.setName("MyDialog")

        self.setSizeGripEnabled(1)

	self.build_window()

    def build_window(self):

	toplayout = QGridLayout(self,1,1,11,6,"toplayout")
        vbMain = qt.QVBox(self)
	toplayout.addWidget(vbMain, 0, 0)

        sview = qt.QScrollView(vbMain)
	vp = sview.viewport()
	vbox = qt.QVBox(vp)
        sview.addChild(vbox)

	vplayout = qt.QGridLayout(vp, 0, 0, 1,-1, 'vpl')
	vplayout.addWidget(vbox, 0, 0)

	grid = qt.QGridLayout(vbox.layout(), 2, 2)

	ll = qt.QLabel('circuit name', vbox)
	grid.addWidget(ll, 0,0, qt.Qt.AlignLeft)

	nameinput = qt.QLineEdit(vbox)
	grid.addWidget(nameinput, 0,1, qt.Qt.AlignLeft)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    f = MyDialog()
    f.show()
    app.setMainWidget(f)
    app.exec_loop()





More information about the Python-list mailing list