Results 1 to 3 of 3

Thread: Limit number of row/column in QGridLayout

  1. #1
    Join Date
    Oct 2007
    Location
    Quebec, Canada
    Posts
    40
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Limit number of row/column in QGridLayout

    First of all, hello to everyone, I'm a newbie hehe.

    Just began integration of Qt in our application and I know this is a stupid question but I can't find the solution and I tried. I even got in the source code which was really interesting.

    I want to use QGridLayout but limit the number of column. I know it was possible in Qt3 but in Qt4, the constructors have disappeared. It would also be nice to do it after contruction if possible as this may change dynamically.

    Also how do I set the default orientation for adding new widget. I looked in the source code and there is setDefaultPositioning but it doesn't seem to do what I want.

    For example, I would like to be able to create a QGridLayout. Set max column number to 3 and add every new item in the next column and switch row when necessary using the default addWidget( Widget* ).

  2. #2
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Limit number of row/column in QGridLayout

    I don't think what you want to do is possible in Qt 4. The only addWidget( ) take in the row/column combination to tell it where to place it as well as the spanning row and column function.

    The only way I can see how you could do this the way you want is to create a variable holding columnNum and rowNum. Then have a number stating MAX_COLS, like a #define or something. After adding a widget, increment columnNum and then when columnNum >= MAX_COLS set columnNum back to 0 and increment rowNum. This is the only way I can think of how you can solve your problem, but I have always just said what row and column to add things to.

    I also don't think this was possible in Qt 3.3 as I have worked a lot in Qt 3.3 and looked in its documentation and the addWidget function requires a row and column be passed in. If you want to just add items without telling space, maybe you should look into using a QHBoxLayout containing "x" number of QVBoxLayouts. But again you would have to store some value stating what column you were on and what the max number of columns are.

    If you don't put any items into a column, that column will not exist. So if you only add items to columns 0-2 then only columns 0-2 will show. Then later on if you add something to column 3, then 0-3 will all be visible. If no items are in a column or column after it, the column will not exist.

  3. #3
    Join Date
    Oct 2007
    Location
    Quebec, Canada
    Posts
    40
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Limit number of row/column in QGridLayout

    QLayout has addWidget( Widget* ) which calls virtual addItem( QLayoutItem* ) which is defined in QGridLayout. I saw some code about positioning and updating next insert pos, I just can't find how to set the maximum number of rows and columns.

Similar Threads

  1. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 07:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.