Qt6 topics merged with General

QTabWidget undocked and floating tab

  • Hello friends.

    Today I come for the following:

    I have an implementation of tabs to which I want to add the following functionality:

    1-. By double clicking on any tab, I want it to become a floating window.
    2-. That the floating window is dependent on the main window of course.
    3-. The tab in question is removed from the QTabWidget.

    For now, point 3 I have already solved, reimplementing the mouseDoubleClickEvent event to get the index of the selected tab and remove the QTabWidget tab.

    In point 1, I have a small implementation to perform such a task, but the resulting window turns black and gives the appearance of being permanently repainted, in addition to this, control is lost because when the application is closed the new floating window does not close, which makes me think that point 2 is not being met.

    If I uncomment the line // tab-> setFloating (true); this is the result:

    Window Floating From QTabWidget Bad Painting

    As you can see, a whole black stripe on top

    This is the code of my mouseDoubleClickEvent method of my DockBar class (QTabBar)

    void DockBar::mouseDoubleClickEvent ( QMouseEvent *event ) {
      if ( event->button () == Qt::LeftButton ) {
        DockerWindow *tab = ( DockerWindow * ) ( ( Dock * ) this->parentWidget () )->widget ( this->currentIndex () );
        ( ( Dock * ) this->parent () )->removeTab ( this->currentIndex () );
        //tab->setFloating ( true );
        tab->setParent ( ( ( Workspace * ) ( ( Dock * ) this->parentWidget () )->parentWidget () )->parentWidget () );
        tab->setWindowFlags ( Qt::Window );
        //tab->repaint ();
        tab->show ();

    This code generates the following output:

    Window Floating From QTabWidget
    Window Floating From QTabWidget

    Where the first image is my main window with the QTabWidget that I have implemented, and the second one is the decoupled window when I double click on the tab.

    And if I use a QDialog, QMainWindow or QFrame the same thing happens in

    Now, the DockerWindow class is a subclass of QWidget which I modified so that my floating window looks like this:

    Custom Window Floating

    and in this way I want the floating window to look, but it looks black

    Well, what am I doing wrong?
    What can I do to achieve point 1 and 2?

    In addition to this I attach a compilable of my problem in question and until now the problem is presented in line 130 of the file DockBar.cpp, if I comment it, all "nice", but if not, the black window.

    I can't upload files :(


  • I have found that the window turns black when floating is caused by the resizeEvent of the DockerWindowTitleBar.

    You set the title bar to a fixed width.
    Maybe there are some points that the widget's width become large, and you set the width at that time.

    As for the point 2, the floating window is closed when the application is closed in my computer.

  • @Flotisable
    Hello Flotisable.

    Thanks for your answer.

    In fact they are right, the problem was in the coding of the resizeEvent method.

    I've already solved it by removing the setting from the title bar.

    Definitely a fresh head is the best solution to visualize what one does not see.

    Thank you so much for everything.

Log in to reply