Results 1 to 3 of 3

Thread: Non-exclusive stack layout

  1. #1
    Join Date
    Aug 2012
    Location
    Wrocław, Poland
    Posts
    25
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question Non-exclusive stack layout

    Qt offers QStackedLayout/QStackedWidget but they are exclusive: only a one page can be visible at a time. While I need one that has all pages visible at all the time. What are my options here?

    My scenario started simpler. At first I had a combo box that selects a type and based on that QStackedWidget showed appropriate page. To make it work as I wished I located the QStackedWidget in a QVBoxLayout of the main widget. (That way the QStackedWidget resized properly with the main widget.) The combo box was a separate widget also located within the main widget but outside of QVBoxLayout. It is difficult to make it in the Designer (at least for me) but you can do that easly in UI file itself, then the Designer shows it properly. Since the combo box and QStackedWidget overlapped I set proper z-order. It seemed to work provided that I took care while designing widgets for the pages that there is free space where the combo box is located.

    But then things got complicated. I needed to add another widget to the main widget in the similar way as the combo box, so that it will overlap with the QStackedWidget. The difficult part was that unlike the combo box which was located in left-top corner the new widget had to be located in top-right corner. And that requires care with resizing the main widget since that newly added widget would have to be relocated as well. I wanted to avoid doing that in code since it should be done by layouts. And so the journey starts!

    (Now when I think about it I could have made it simpler if I would have used QStackedLayout instead of QStackedWidget within "artificial" QVBoxLayout. I didn't do that because Designer doesn't offer QStackedLayout in its tool box. Why? Also it wouldn't change anything relating the issue presented here.)

    My first attempt was to have the combo box and newly added widget joined in a QHBoxLayout with spacer inside. That would be perfect. If not for widget limitation of having only a single layout and that was already allocated for QVBoxLayout storing QStackedWidget. Removing that QVBoxLayout wouldn't help because I would end with the very same problem only with QStackedWidget instead of the newly added widget (since QStackedWidget also needs to resize along the main widget).

    Then I looked for a different layout but it seems no other layout does what I need.

    So I considered writing my own layout. Especially that there is already an example of CardLayout that does a similar thing. But here the question was how to add a custom layout to UI file and Designer? Before versions 5.0 it seems this wasn't supported. Is this supported now?

    Are there any better solutions?

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

    Default Re: Non-exclusive stack layout

    Could you post a mockup image describing what you want to do?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2012
    Location
    Wrocław, Poland
    Posts
    25
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Non-exclusive stack layout

    Quote Originally Posted by wysota View Post
    Could you post a mockup image describing what you want to do?
    Here you go:

    Screen.png

    Note that this screen from actual experimental code. Some things are not well yet (like the type combo box is not well aligned with other controls).

    The type combo box (and now also the new widget) are supposed to stay there where they are. Also the new widget should be anchored to the right edge of the main widget. As I described I would like those two to behave as if they were in a single QHBoxLayout with a spacer in between.

    While the remaining widgets are provided by some other widget placed as a page in QStackedWidget that is stretched on the main widget bellow (z-order) the combo box (and now also the new widget). There will be multiple pages in that QStackedWidget with various controls on each page lay out in various ways. Yet I expect most of them to place additional data on the line between type combo box and the new widget.

    The new widget will be hide/show details. When hidden only the controls on the type combo box - the new widget will be shown.

Similar Threads

  1. How to make QPushbuttons with same parent non-exclusive
    By davethomaspilot in forum Newbie
    Replies: 4
    Last Post: 9th December 2012, 21:33
  2. Syncing QTextDocument's undo stack with custom undo stack
    By Dini Selimović in forum Newbie
    Replies: 0
    Last Post: 24th June 2012, 13:11
  3. QTableWidget exclusive cells
    By bwnicewo in forum Qt Programming
    Replies: 1
    Last Post: 30th May 2012, 00:25
  4. how exclusive toolbutton in toolbar
    By irmakci in forum Qt Programming
    Replies: 2
    Last Post: 30th July 2008, 22:33
  5. exclusive checkBox
    By mickey in forum Qt Programming
    Replies: 6
    Last Post: 4th October 2007, 18:26

Tags for this Thread

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.