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. QTabWidget undocked and floating tab
QtWS25 Last Chance

QTabWidget undocked and floating tab

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 3.0k Views
  • 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.
  • R Offline
    R Offline
    remizero
    wrote on last edited by remizero
    #1

    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 :(

    https://drive.google.com/open?id=1xtV0HCzeGbNW4vJ7WwG-fEsZb3aSNa2A

    1 Reply Last reply
    0
    • FlotisableF Offline
      FlotisableF Offline
      Flotisable
      wrote on last edited by
      #2

      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.

      R 1 Reply Last reply
      2
      • FlotisableF Flotisable

        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.

        R Offline
        R Offline
        remizero
        wrote on last edited by
        #3

        @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.

        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