QDockWidget allowed areas in QMainWindow



  • Hi everyone (and sorry for my bad english),

    I have a MainWindow (allow nested, allow tabbed) with 3 DockWidgets created with the designer. The first one that can only be floating or docked on the left, another one which can only be floating or docked on the bottom, and the third can only be dock on top or right and not floating.

    My problem is that at runtime I add tabwidgets on the third one, which works great, but even if I set its allowed areas not to dock on left or bottom, i can "tab" them to the left and bottom with the two others created with the designer.

    Anybody had encounter this problem already ?

    Thanks for your reply :)

    [EDIT] I catch the signal dockLocationChanged with slot in my main window and everywhere I dock the widget, the new area is always the Top...



  • Anyone ?? :(



  • Hi there,

    First of all, your English is perfectly understandable, so don't worry about that :)

    Your problem, however, not so much :D

    I don't quite understand what you mean with the following:

    [quote author="jpalbertini" date="1359113800"]
    My problem is that at runtime I add tabwidgets on the third one, which works great, but even if I set its allowed areas not to dock on left or bottom, i can "tab" them to the left and bottom with the two others created with the designer[/quote]

    Do you create the third dock widget dynamically, or do you only set its contents? Also, I am not sure what you mean with "tab" them to the left or bottom.

    It would be very cool if you could provide a minimal example of your code.



  • Thanks for your reply :)

    The third dock widget is created with the designer.

    When I say that I tab them, I mean that I add them to my main window, and then I "tabify" them with my third widget (dockMainWidget), which act like an anchor...

    Note that in the folowing code, the TabWidget is a class heriting from QDockWidget (which can be prety confusing)

    @void MainWindow::addTab(TabWidget * page)
    {
    page->setFocusPolicy(Qt::StrongFocus);
    page->setAllowedAreas(Qt::RightDockWidgetArea | Qt::TopDockWidgetArea);

    this->addDockWidget(Qt::RightDockWidgetArea, page);

    this->tabifyDockWidget(dockMainWidget, page);
    this->setTabOrder(page, dockMainWidget);

    page->setVisible(true);
    page->setFocus();
    page->raise();

    connect(page,SIGNAL(changed(TabWidget )),this,SLOT(tabWidgetChanged(TabWidget)));
    connect(page, SIGNAL(closed(QString)), this, SLOT(closeTab(QString)));

    mTabWidgets.insert(page->key(), page);
    actionClose_current_tab->setEnabled(true);
    page->setAllowedAreas(Qt::RightDockWidgetArea | Qt::TopDockWidgetArea);

    connect(page, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(dockLocChanged(Qt::DockWidgetArea)));
    }@



  • I'm sorry, but there are too many variables falling outside of the scope of what you provided for me to figure out what is happening and where it is going wrong (the only noticable error is that you call setAllowedAreas() twice, but you call it with the same parameters each time so although unnecessary, it shouldn't have any effect or bearing on your problem).

    To be honest, I still don't fully understand what you are trying to achieve either. Are you trying to add dockwidgets as tabs to a tab widget? So that you can undock each tab independent of the others?



  • Yes that's exactly what I am trying to do, add dock widgets as tabs to a staticaly defined dock widget so I dock and undock them individually.

    My problem is that when I add a dockwidget it can be docked everywhere and not only at Right or Top.

    The thing is everytime I go to the slot dockLocChanged of the main window, the value of the "area" parameter that I receive from the signal is always 4, which is the value of TopWidgetArea, even if I dock the dock widget with a dock widget which is in LeftWidgetArea

    The setAllowedAreas is called twice, just to make sure :)

    code of the slot:

    @void MainWindow::dockLocChanged(Qt::DockWidgetArea area)
    {
    qDebug() << "widget area changed " << (static_cast<TabWidget*>(sender()))-> title() << " to area: " << area;
    qDebug() << "widget allowed areas: " << (static_cast<TabWidget*>(sender()))->allowedAreas();

       qDebug() << "info allowed area  " << dockInfoWidget->allowedAreas() << " , docked: " << !dockInfoWidget->isFloating();
       qDebug() << "tree allowed area  " << dockTreeViewWidget->allowedAreas() << " , docked: " << !dockTreeViewWidget->isFloating();
       qDebug() << "main view allowed area  " << dockMainWidget->allowedAreas() << " , docked: " << !dockMainWidget->isFloating();
    

    }@



  • Any chance that you could provide a minimal, compilable version of your application?



  • no sorry can't do that...



  • Ok, I haven't actually tried this example, but at first glance it seems relevant and perhaps it can help:

    "Qt Main Window Demo":http://doc.qt.digia.com/4.7/demos-mainwindow.html

    Good luck! :)



  • Thanks, i found the problem:

    The central widget of my main window was invisible under the widget docked in bottom, so all the docks where on top of the central widgets, therefore they can be dockable everywhere....

    I am now trying to modify the central widget so its height would be equal to 0 but even by settings its maximum size, it can shrink to 0 manually but it is not shrink at startup and it can take every size possible...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.