Results 1 to 5 of 5

Thread: best layout fo a fixed part (on the left) and a dynamic part (on the right)

  1. #1
    Join Date
    Apr 2019
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default best layout fo a fixed part (on the left) and a dynamic part (on the right)

    HI,
    I'm new in pyqt5 and I'm going to realize a GUI where on the left I have 3 buttons and on the right I could have different widgets depending on which button has been pushed.
    Scenario looks like this

    BUTTON 1 |
    BUTTON 2 | DYNAMIC AREA
    BUTTON 3 |

    In this scenario, where the left part is fixed (I'll always have the 3 buttons) and on the right I will have different widgets, which is the best layout to use?

    The grid layout?

    Thanks,
    M

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,294
    Thanks
    36
    Thanked 1,521 Times in 1,472 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: best layout fo a fixed part (on the left) and a dynamic part (on the right)

    Maybe QVBoxLayout on the left side, a QStackWidget on the right side.

    Cheers,
    _

  3. #3
    Join Date
    Apr 2019
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: best layout fo a fixed part (on the left) and a dynamic part (on the right)

    Ok, thank you.
    If I'm not wrong, I need a parent layout that in my case could be a QHBoxLayout, which will contain a QVBoxLayout (the lest panel) and a QStackWIdget (on the right panel). Maybe I'm wrong since the QStackWidget is not a layout.
    Two more questions.
    Any time a button is click on the left panel, I have to remove all widgets in the right panel. Should I looking for any widget in the right panel and delete it one-by-one?
    May I add a vertical line between the left panel and the right one?
    Thanks for your support and patience.
    M
    Last edited by mcanonic; 16th May 2019 at 10:05.

  4. #4
    Join Date
    Jul 2008
    Posts
    394
    Thanks
    9
    Thanked 50 Times in 48 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: best layout fo a fixed part (on the left) and a dynamic part (on the right)

    Hi, the QStackWidget has multiple pages, but it displays only one of these pages at a time. So instead of deleting any widgets on your right panel, you arrange your widgets on different pages (one for each button) and simply change the page of the QStackWidget when a button is clicked.

    To draw a line use QFrame with QFrame::VLine as shape, or try a QSplitter.

    Ginsengelf

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,294
    Thanks
    36
    Thanked 1,521 Times in 1,472 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: best layout fo a fixed part (on the left) and a dynamic part (on the right)

    Quote Originally Posted by mcanonic View Post
    If I'm not wrong, I need a parent layout that in my case could be a QHBoxLayout, which will contain a QVBoxLayout (the lest panel) and a QStackWIdget (on the right panel).
    Right. Or a QSplitter as Ginsengelf said.

    Quote Originally Posted by mcanonic View Post
    Any time a button is click on the left panel, I have to remove all widgets in the right panel. Should I looking for any widget in the right panel and delete it one-by-one?
    May I add a vertical line between the left panel and the right one?
    Again as Ginsengelf said, the idea about using a QStackWidget is to avoid having to do that.

    Essentially you add your buttons to a QButtonGroup and use the "id" argument to associate the page index on the stack widget side with the button.
    You can then directly connect the buttongroup's buttonClicked(int) signal with the stackedwidget's setCurrentIndex(int) slot and are done.

    Cheers,
    _

Similar Threads

  1. Reading text file line part by part
    By anh5kor in forum Newbie
    Replies: 4
    Last Post: 23rd December 2015, 11:31
  2. Part of QString
    By arturs in forum Newbie
    Replies: 1
    Last Post: 18th July 2015, 16:27
  3. QToolBar Layout(when part of QMainWindow)
    By iridium in forum Qt Programming
    Replies: 3
    Last Post: 18th April 2013, 13:19
  4. Replies: 6
    Last Post: 16th April 2013, 16:13
  5. Replies: 2
    Last Post: 23rd August 2011, 12:23

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.