QLineEdit object does not execute multi-row span



  • Hi again, I have working code this time but I think I might have found a bug. I am working in PyQt 4.4.4 editing in emacs on a UNIX server and running on Windows 7.

    I have:

    @...
    review = QtGui.QLabel('Review')
    ...
    reviewEdit = QtGui.QLineEdit()
    ...
    grid = QtGui.QGridLayout()
    grid.setSpacing(10)
    ...
    grid.addWidget(review, 3, 0)
    grid.addWidget(reviewEdit, 3, 1, 5, 1)

           self.setLayout(grid)
    
           self.setGeometry(300,300,350,300)
           self.setWindowTitle('Review')
           self.show()
    

    ...
    @

    The program runs and produces a very nice window with three lines for input (title, author and review). The review box is supposed to span from row 3 to row 5. However, it actually locates a single line box at row 5. (Can I upload screen grabs here? This is work related and I can't access any personal storage at work, so I can't give a link to a dropbox-like location)

    I tried setting
    @grid.addWidget(reviewEdit, 3, 1, 0, 1)@

    and I got the error "Multi-cell fromRow greater than toRow", which is good because it means that the arguments are what I think they are and they are in the order that I thought they should be. However, if I set toRow >= 3, I don't get a box that is multi-rows long, I get a box one line long set to the toRow position.

    PS: I just made an edit to my post and instead of "preview post", I did C-x C-s ... time to go home.

    EDIT: I wish I could upload a gif animation! I have tried the following cases. The only thing that changes is the last line, so I am including the others only once:
    First
    @
    grid = QtGui.QGridLayout()
    grid.setSpacing(10)

        grid.addWidget(title, 1, 0)
        grid.addWidget(titleEdit, 1, 1)
    
        grid.addWidget(author, 2, 0)
        grid.addWidget(authorEdit, 2, 1)
        
        grid.addWidget(review, 3, 0)
        grid.addWidget(reviewEdit, 3, 1)
    

    @
    Second
    @
    grid.addWidget(reviewEdit, 3, 1, 3, 1)
    @
    Third
    @
    grid.addWidget(reviewEdit, 3, 1, 5, 1)
    @
    Fourth
    @
    grid.addWidget(reviewEdit, 3, 1, 7, 1)
    @
    Fifth
    @
    grid.addWidget(reviewEdit, 3, 1, 9, 1)
    @

    I took screen grabs of each one and pasted them into a Power point and scrolled through. This is what is happening: The first one has three evenly spaced label/labelEdit pairs with a lot of spacing between them (more than the 10 dictaged by grid.setSpacing(10)). After this, the spacing seems to be ignored. The second through fifth tries appear to place title+titleEdit on the first row, author+authorEdit on the second row, and reviewEdit on the seventh row (what?). What is changing with each new try is that the review label is moving up. Second try: review at row 5, third try: review at row 4, fourth try: review at row 3.5, fifth try review at row 3.

    I know that row indices are integers, but I am trying to describe the visual change I saw. Each higher number raises the review label by less than the previous change had. There is no change between 10 and any higher number. It seems like toRow (I'm using the term I see in the error message, I know it's not standard Qt terminology) is controlling the vertical space between the label and the line entry box, rather than the number number of rows spanned by the entry box. After 10, it runs into the maximum vertical size of the window from setGeometry, which is 350 pixels and stops having an effect.


  • Moderators

    I don't know much about PyQt, but a regular QGridLayout takes a "from row" and "row span", not "to row", so if you wan't to span across rows 3-5 you would do
    @
    grid.addWidget(reviewEdit, 3, 1, 3, 1)
    @



  • I've already tried this and it gives me the same results. See the Edit to my post.



  • Hi there,

    I was following some tutorials to learn PySide and had the exact same issue until I figured out the solution (the tutorial thinks you can just give a lineEdit a rowSpan value... oh no you can't!)

    The problem is that the default size policy for the lineEdit widget allows horizontal, but not vertical scaling.

    Have a look at QtGui.QSizePolicy() in the docs, also QtGui.QSizePolicy.Policy

    The solution I found is to create your own size policy object that allows horizontal and vertical sclaing, then set the lineEdit widget size policy to that:

    reviewEdit = QtGui.QLineEdit()
    mySizePolicy = QtGui.QSizePolicy()
    mySizePolicy.setVerticalPolicy(QtGui.QSizePolicy.Policy.Expanding)
    mySizePolicy.setHorizontalPolicy(QtGui.QSizePolicy.Policy.Expanding)
    reviewEdit.setSizePolicy(mySizePolicy)

    Cheers,
    Matt.



  • ...although having thought about this some more, I actually think that QLineEdit simply isn't an appropriate widget to rowSpan as it is inherently a single line text field in its behaviour, even when vertically stretched using the above method.

    I suspect using a more appropriate scrolling text field widget which is inherently multi-line (I'm just learning this stuff, so not dug this out) would rowSpan automatically.

    Matt.



  • This post is deleted!

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.