Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Mainwindow layout problem with QDockWidget.
Forum Updated to NodeBB v4.3 + New Features

Mainwindow layout problem with QDockWidget.

Scheduled Pinned Locked Moved General and Desktop
18 Posts 8 Posters 21.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pastispast
    wrote on last edited by
    #1

    Hi Friends,

    I have to create a custom layout for my main application. Layout can be of different type as:

    @
    |-----------------------|
    | | | | |
    | 1 | | 4 | 6 |
    |-----| 3 |-----|----|
    | | | | |
    | 2 | | 5 | 7 |
    |-----------------------|
    | 8 |
    |-----------------------|
    or

        |-----------------------|
        |     |           |     |
        |  2  |           |  4  |
        |-----|     1     |-----|
        |     |-----------|     |
        |  3  |     7     |  5  |
        |-----------------------|
        |           6           |
        |-----------------------|
    

    @

    Here all no's(1...) are the dockwidgets. But I am facing following problems to do so:

    1. As DockWidgetAreas have only the following layout option:

    Qt::LeftDockWidgetArea
    Qt::RightDockWidgetArea
    Qt::TopDockWidgetArea
    Qt::BottomDockWidgetArea
    Qt::AllDockWidgetAreas DockWidgetArea_Mask
    Qt::NoDockWidgetArea

    then how can I add the position for other windows.

    1. Positioning of the 'QDockWidget': When I am positioning the docs using the move and resize functions then it does not work properly.

    Note:
    I have done the following try:

    • I have tried the sizeHint() and save/load geometry but it does not worked.

    • I have tried the layout on centerwidget using splitter and gridlayout but it does not give me the proper docking feature as the dock windows was the child of centerwidget.

    Please provide me some idea or solution on this issue....thanks in advance...

    1 Reply Last reply
    1
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Are you sure you really want QDockWidgets? These are meant to be rearranged/moved and even put as toplevel windows by the user.

      From what I see, I would suggest that you go with a grid layout, its items can span multiple columns or rows if needed. You can easily create it with Qt Designer (stand alone app) or the built in designer of Qt Creator.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pastispast
        wrote on last edited by
        #3

        Hi Volker...thanks for the reply.

        Actually I need the following behavior for the windows:

        • Dock/Undock.
        • Move and Auto-dock to some area while dragging the windows.

        that's why I have to use QDockWidget (Layout like a visual studio IDE).

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          Seems to me that this is not possible. There is only one "row" of dock widgets designated around the central widget of a QMainWindow.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • E Offline
            E Offline
            entuland
            wrote on last edited by
            #5

            I think I've been able to build both of the OP's layouts by flagging AllowNestedDocks in the dockOptions section of the QMainWindow's properties - though, I did that at runtime, just by moving dockwidgets around, I have no idea about how to get the same results with plain code... HTH!

            1 Reply Last reply
            0
            • E Offline
              E Offline
              entuland
              wrote on last edited by
              #6

              Uhm... not exactly the same layouts, but something along the lines... anyway, nested docks are definitely something to play with :-)

              [edit]
              just for a visual hint about what is certainly possible at runtime, here is one of the layouts I've been able to compose:
              @
              +---+---+---------+---+---+---+
              | | | | | | |
              | 1 | 2 | | 5 | 6 | 7 |
              | | | central | | | |
              +---+---+ +---+-+-+---+
              | | | widget | | |
              | 3 | 4 | | 8 | 9 |
              | | | | | |
              +---+---+----+----+-----+-----+
              | | |
              | 10 | 11 |
              | | |
              +------------+----------------+
              @
              [/edit]

              1 Reply Last reply
              0
              • E Offline
                E Offline
                entuland
                wrote on last edited by
                #7

                Found it: you can define the disposition of those nested docks by repeatedly calling QMainWindow::splitDockWidget() and passing to it two docks each time (the one whose space you want to split, and the one you want to add as a sibling, along with the orientation of the arrangement you want to get).

                It may take some time to figure out the exact order of calls, but it can be done (you don't even need to activate the option to allow nested docks, as it seems it only affects the manual arrangement at runtime).

                A snippet:
                @
                void MainWindow::on_pushButton_clicked() {
                splitDockWidget(ui->dockWidget, ui->dockWidget_3, Qt::Horizontal);
                splitDockWidget(ui->dockWidget, ui->dockWidget_2, Qt::Vertical);
                }
                @

                Something like the above will work (assuming appropriate context) to arrange the first three docks of the first OP's layout.

                The above function calls will produce different results (or no results at all) depending on the state and position of each dock, so you might need to explicitly un-float or move to the appropriate side each dock, before splitting the space they occupy.

                1 Reply Last reply
                1
                • P Offline
                  P Offline
                  pastispast
                  wrote on last edited by
                  #8

                  Hi entuland, thanks for the reply…

                  that helps a lot…thanks for this…

                  In the above way, can I make “central widget” also as a QDockWidget, while doing this I am facing following constraints:

                  Constraint1: I have to make “centralwidget” as a parent of QDockWidget. But in this case docking/undocking not works properly (because centralwidget is the parent not mainwindow).

                  Constraint2: If I use setCentralWidget(0) then I have docking size/resize issue.

                  Constraint3: One more thing here that “centralwidget” always take the huge space of the layout. If there a way to restrict it or properly managed.**

                  1 Reply Last reply
                  1
                  • T Offline
                    T Offline
                    tobias.hunger
                    wrote on last edited by
                    #9

                    Do you really want 11 dockwindow areas? As a user I would get terribly confused by that!

                    1 Reply Last reply
                    0
                    • E Offline
                      E Offline
                      entuland
                      wrote on last edited by
                      #10

                      @pastispast: you're welcome, I'm glad to help when I can.

                      Unfortunately I cannot help you further with the issues of your layout, I can only suggest you to put something different as a central widget, not a dockwidget, so that your users are well aware of what is the main content of your program and where the docks can be put - also, practice a bit more with the interface, your constraint 3 does not stand: it's you who decide how much space the central widget takes, you can put a lot of stuff in the central widget yet make it completely disappear (that is, 0x0 size) by just resizing the docking areas, assuming you use appropriate settings for the size restrictions.

                      @Tobias Hunger: it all depends on the type of the program and on the intended audience, I feel comfortable with lots of docks as long as I'm able to move, resize and hide them at will - just like you would feel comfortable with, I think - but if I was Average User, I think I could get confused too... only the OP can decide whether such an amount of docks is appropriate or not, since we don't know the context of the program at hand.

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        dangelog
                        wrote on last edited by
                        #11

                        Actually, I'm missing something like Adobe Premiere dockings in Qt :-)

                        Software Engineer
                        KDAB (UK) Ltd., a KDAB Group company

                        1 Reply Last reply
                        0
                        • E Offline
                          E Offline
                          entuland
                          wrote on last edited by
                          #12

                          Unfortunately I never used Adobe Premiere... could you describe the features you're thinking about, peppe?

                          1 Reply Last reply
                          0
                          • D Offline
                            D Offline
                            dangelog
                            wrote on last edited by
                            #13

                            See f.i. http://filmmakingcentral.com/fmc2/wp-content/uploads/2008/12/premui1.jpg , basically there are ONLY docked widgets with an unique look and feel, and quick menus everywhere to switch their layouts and add/remove them on the fly (with many presets available).

                            Software Engineer
                            KDAB (UK) Ltd., a KDAB Group company

                            1 Reply Last reply
                            0
                            • E Offline
                              E Offline
                              entuland
                              wrote on last edited by
                              #14

                              Looks quite interesting... well maybe we could subclass QDockWidget and add some functionality... it may become an interesting spare time project :-)

                              1 Reply Last reply
                              0
                              • osirisgothraO Offline
                                osirisgothraO Offline
                                osirisgothra
                                wrote on last edited by
                                #15

                                heads up, please use fixed width fonts when trying to convey design layouts to others, or put it in an image, because variable-width fonts hardly ever line up as they do for you on the other end (even if it does go ok in fixed width, but not everyone sees it this way). Maybe someone can fix this problem on the 'code view' either that or i'm the only one, if I am, just smack me.

                                I'm truly glad you r/offmychess t finally, but please don't go too far, because you r/beyondvoxels and that implies that u r/donewithlife. Oh well time to git back to the lab, because azure sea here, I have a lot of work to do...

                                1 Reply Last reply
                                0
                                • 1 Offline
                                  1 Offline
                                  10QT
                                  wrote on last edited by
                                  #16

                                  Any update on this? Is there a way to have only dockable windows like the adobe example?

                                  1 Reply Last reply
                                  0
                                  • Chris KawaC Offline
                                    Chris KawaC Offline
                                    Chris Kawa
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #17

                                    @10QT said:

                                    Is there a way to have only dockable windows like the adobe example?

                                    To some degree - yes. The key is creating a dummy 0 size central widget and enabling nested docks dockable to only single dock area (e.g. top). Here's an example:

                                    #include <QMainWindow>
                                    #include <QDockWidget>
                                    #include <QApplication>
                                    
                                    int main(int argc, char *argv[])
                                    {
                                        QApplication a(argc, argv);
                                    
                                        QMainWindow w;
                                        w.setDockOptions(QMainWindow::AllowNestedDocks | QMainWindow::AllowTabbedDocks);
                                    
                                        w.setCentralWidget(new QWidget());//just a dummy
                                        w.centralWidget()->setMaximumSize(0,0);
                                    
                                        auto d1 = new QDockWidget("Foo");
                                        d1->setAllowedAreas(Qt::TopDockWidgetArea);
                                        w.addDockWidget(Qt::TopDockWidgetArea, d1);
                                    
                                        auto d2 = new QDockWidget("Bar");
                                        d2->setAllowedAreas(Qt::TopDockWidgetArea);
                                        w.addDockWidget(Qt::TopDockWidgetArea, d2);
                                    
                                        auto d3 = new QDockWidget("Bazz");
                                        d3->setAllowedAreas(Qt::TopDockWidgetArea);
                                        w.addDockWidget(Qt::TopDockWidgetArea, d3);
                                    
                                        auto d4 = new QDockWidget("Hello");
                                        d4->setAllowedAreas(Qt::TopDockWidgetArea);
                                        w.addDockWidget(Qt::TopDockWidgetArea, d4);
                                    
                                        auto d5 = new QDockWidget("Bye");
                                        d5->setAllowedAreas(Qt::TopDockWidgetArea);
                                        w.addDockWidget(Qt::TopDockWidgetArea, d5);
                                    
                                        auto d6 = new QDockWidget("Hi there");
                                        d6->setAllowedAreas(Qt::TopDockWidgetArea);
                                        w.addDockWidget(Qt::TopDockWidgetArea, d6);
                                    
                                        w.splitDockWidget(d1, d2, Qt::Vertical);
                                        w.splitDockWidget(d3, d4, Qt::Vertical);
                                        w.splitDockWidget(d3, d5, Qt::Horizontal);
                                        w.tabifyDockWidget(d1, d6);
                                    
                                        w.show();
                                        return a.exec();
                                    }
                                    

                                    This results in:
                                    Nested docks layout

                                    Presets and buttons for switching docks positions you can get by subclassing QDockWidget and customizing it.

                                    1 Reply Last reply
                                    1
                                    • 1 Offline
                                      1 Offline
                                      10QT
                                      wrote on last edited by
                                      #18

                                      Thanks for the quick reply, I'll give this a try

                                      1 Reply Last reply
                                      0

                                      • Login

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • Users
                                      • Groups
                                      • Search
                                      • Get Qt Extensions
                                      • Unsolved