Results 1 to 20 of 20

Thread: Resizable Frames/Layouts

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Resizable Frames/Layouts

    Hey, I couldn't find the answer while searching the forum, so I apologize if it's been brought up before.

    I have a TreeView in one VBoxLayout, and then a TextEdit in a VBoxLayout on the bottom, I also have a TableView on the big box on the top left.
    ______
    |---||--|
    |__||--|
    [__]|_|

    Basically looks like that, if the spacing works out. Small text box on the bottom left. A Treeview covering the right half. And in the top left a large area of TableView.

    What I need to do is, when someone resizes the whole window. I want them to be able to resize the TreeView, TextEdit, and TableView all at same time. Right now it stays the same size.

    I can't post the large amount of code I created, as it would be confusing, but I understand your code, so if you know what functions to use, or a code example, it would be great, thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Resizable Frames/Layouts

    Did you set a layout for the form itself?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Resizable Frames/Layouts

    Consider using a single grid layout.

  4. #4
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Resizable Frames/Layouts

    I just AddWidget all three things? Then change the Column stuff? Any Examples?

    THanks tho.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Resizable Frames/Layouts

    Quote Originally Posted by VireX View Post
    I just AddWidget all three things? Then change the Column stuff?
    Yes.

    Quote Originally Posted by VireX View Post
    Any Examples?
    Qt Code:
    1. setLayout( l );
    2. l->addWidget( _treeView, 0, 0 );
    3. l->addWidget( _textEdit, 1, 0 );
    4. l->addWidget( _tableView, 0, 1, 2, 1 );
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Resizable Frames/Layouts

    setLayout is for some reason undefined. Maybe because my class is made with qtdesigner and is not an extension of QWidget? Also I changed the addWidget to addLayout.

    What about QSplitter?

    Since setLayout alone didn't work I did this...
    The code in my setupUi() function: (qglMain = QGridLayout*)
    Qt Code:
    1. qglMain->addLayout(vboxLayout, 0,0);
    2. qglMain->addLayout(vboxLayout1, 1,0);
    3. qglMain->addLayout(vboxLayout3, 0, 1, 2, 1);
    4. MainWindow->setLayout(qglMain);
    To copy to clipboard, switch view to plain text mode 

    However, now it just crashes.
    Commenting the setLayout line, still makes it crash.
    Last edited by VireX; 18th March 2007 at 01:27.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Resizable Frames/Layouts

    What is "qglMain"? setLayout is defined in QWidget class, but we're assuming your widget is a widget if you create an ui in Designer, you later wrap it into a class inheriting QWidget (or one of its subclasses). That's the moment to put the above mentioned code. But if you use Designer, then simply click on the form (so that no items are selected) and click on "Lay out in a grid" icon in the toolbar.

  8. The following user says thank you to wysota for this useful post:

    VireX (18th March 2007)

  9. #8
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Resizable Frames/Layouts

    I said qglMain = QGridLayout*..

    Also I tried your designer trick... But now:
    [_]| |
    [_]|__|
    It looks like it seperated everything into 3 boxes. It looks horrible, because the Treeview on the right is so big. I cannot change the size of the userlist, or any of the grid cells.

    Why shouldn't I touch the code of ui, I want to change something I don't want to reopen designer and fix it, because it's something in the code.

    Also, I tried the QSplitter approach, (yes I thought of 2 of them too) and then all my stuff just disappeared I couldn't see my results, just a blank window.
    The QGridLayout approach, just makes my program crash. And using layouts in Designer sucks, so I like to code the layouts instead it's easier to see.
    Last edited by VireX; 18th March 2007 at 01:54.

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Resizable Frames/Layouts

    Quote Originally Posted by VireX View Post
    Also I tried your designer trick... But now:
    [_]| |
    [_]|__|
    It looks like it seperated everything into 3 boxes. It looks horrible, because the Treeview on the right is so big. I cannot change the size of the userlist, or any of the grid cells.
    Tweaking the hSizeType, vSizeType, horizontalStretch and verticalStretch properties for each widget should help.

    Quote Originally Posted by VireX View Post
    Why shouldn't I touch the code of ui,
    Because you will loose all changes when you change the .ui file.

    Quote Originally Posted by VireX View Post
    I want to change something I don't want to reopen designer and fix it, because it's something in the code.
    But you are fixing the results, not the causes.

    Quote Originally Posted by VireX View Post
    Also, I tried the QSplitter approach, (yes I thought of 2 of them too) and then all my stuff just disappeared I couldn't see my results, just a blank window.
    What did you do exactly? To add a splitter, you have to select two widgets and click "Lay out ... in Splitter". After you create all the splitters, you have to add a top-level layout.

    Quote Originally Posted by VireX View Post
    And using layouts in Designer sucks,
    No, it doesn't. You just have to learn how to use them.

    Quote Originally Posted by VireX View Post
    so I like to code the layouts instead it's easier to see.
    I think it's easier to see it on a live widget in the Qt Designer.

  11. The following user says thank you to jacek for this useful post:

    VireX (18th March 2007)

  12. #10
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Resizable Frames/Layouts

    Yes you're right, it's easier to see it live. But some things I haven't learned to control yet, like layout, I keep trying to change the damn size on the splitter in Designer and can't do it. It won't let me push the center split to the right. I even tried the sizepolicy :
    hSizeType, vSizeType, horizontalStretch and verticalStretch, when you change these nothing happens.
    How do I move the splitters (horizontal) middle split to the right by like 200 px?

    It keeps cutting off my long Text box at the bottom, and keeps the treeview so huge... Because it fixes the splitter so that it's centered in between both the widgets.

  13. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Resizable Frames/Layouts

    Quote Originally Posted by VireX View Post
    But some things I haven't learned to control yet, like layout,
    It doesn't mean something sucks just because you haven't learned to use it.

    I keep trying to change the damn size on the splitter in Designer and can't do it.
    And you won't be able to. You can't control the initial size of the splitter - it'll adjust itself according to the widgets it holds.

    It won't let me push the center split to the right. I even tried the sizepolicy :
    hSizeType, vSizeType, horizontalStretch and verticalStretch, when you change these nothing happens.
    Set the horizontalStretch of the left part to the same value as the horizontalStretch of the right part.

    How do I move the splitters (horizontal) middle split to the right by like 200 px?
    By using QSplitter::setSizes() in your code.

    It keeps cutting off my long Text box at the bottom, and keeps the treeview so huge... Because it fixes the splitter so that it's centered in between both the widgets.
    That's what you have size policies for.

  14. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Resizable Frames/Layouts

    Is the attached UI more or less what you wanted?
    Attached Files Attached Files

  15. #13
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Resizable Frames/Layouts

    Quote Originally Posted by wysota View Post
    It doesn't mean something sucks just because you haven't learned to use it.
    No, because some programs have a steeper learning curve than others. They could have made it as simple as making tables in dreamweaver but decided that was not a good idea.
    I didn't say it sucked anyway, I said it sucks to make layouts in it, which is true.
    Quote Originally Posted by wysota View Post
    And you won't be able to. You can't control the initial size of the splitter - it'll adjust itself according to the widgets it holds.
    Which is why I said it sucks making layouts.

    Quote Originally Posted by wysota View Post
    Set the horizontalStretch of the left part to the same value as the horizontalStretch of the right part.
    Adjusting horizontal stretch on either splitter 1 or 2, doesn't change a single thing. Neither does adjusting the sizes of the widgets, or adjusting the other sizePolicy values. They're basically useless in my situation. The splitter vertical line in the middle of my splitter 1 (horizontal) will not budge.

    Quote Originally Posted by wysota View Post
    By using QSplitter::setSizes() in your code.
    I thought you said I could do it in designer.

    Quote Originally Posted by wysota View Post
    That's what you have size policies for.
    Which don't work.

    Also, listen, the untitled ui you gave me...
    Has on one splitter horizontal stretch 1, the rest are 0 on both splitters. I don't understand why 1. And also changing those values doesn't change the layout at all. So I don't believe it controls size at all. Maybe if you tell me what exactly to change on each value to move the
    middle split (vertical) to the right in splitter 2 (the total horizontal splitter) by 150 pixels, and the horizontal middle split in splitter 1 (the smaller vertical splitter) up by 100 pixels...

    EDIT here:
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by VireX; 18th March 2007 at 16:46.

  16. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Resizable Frames/Layouts

    Quote Originally Posted by VireX View Post
    Maybe because my class is made with qtdesigner and is not an extension of QWidget?
    If you created it with Qt Designer, why do you need to add widgets to it? Can't you just add all of the widgets using Designer?

    Also read this very carefully --- it explains how to use the code generated by uic.

    Quote Originally Posted by VireX View Post
    Also I changed the addWidget to addLayout.
    A single QGridLayout is enough in this case. There is no point in having layouts with only one widget inside (except for a top-level layouts). You can do the same using one QVBoxLayout and one QHBoxLayout (see below).

    Quote Originally Posted by VireX View Post
    What about QSplitter?
    You need two splitters. A horizontal one with tree view and text edit and a vertical one with the horizontal spitter and table view.

    Quote Originally Posted by VireX View Post
    The code in my setupUi() function: (qglMain = QGridLayout*)
    You shouldn't touch the code generated by uic.

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
  •  
Qt is a trademark of The Qt Company.