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. How do I hide the window title bar from QDockWidget
QtWS25 Last Chance

How do I hide the window title bar from QDockWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
window titleqdockwidget
34 Posts 7 Posters 10.9k 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.
  • L Offline
    L Offline
    lansing
    wrote on 5 Jul 2020, 14:13 last edited by lansing 7 May 2020, 19:45
    #1

    I want to hide the default "window title" bar that's on top of the dockwidget, I couldn't find the answer anywhere.

    UPDATE: update to a more accurate title for future reference

    R 1 Reply Last reply 9 Feb 2025, 18:58
    1
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 5 Jul 2020, 14:39 last edited by mrjj 7 May 2020, 14:40
      #2

      Hi
      What title bar ??

      alt text

      If you mean when you use it as a window so its shown with the normal border and title then you can do

      setWindowFlags(Qt::Window | Qt::FramelessWindowHint);

      L Y 2 Replies Last reply 5 Jul 2020, 14:58
      2
      • M mrjj
        5 Jul 2020, 14:39

        Hi
        What title bar ??

        alt text

        If you mean when you use it as a window so its shown with the normal border and title then you can do

        setWindowFlags(Qt::Window | Qt::FramelessWindowHint);

        L Offline
        L Offline
        lansing
        wrote on 5 Jul 2020, 14:58 last edited by
        #3

        @mrjj said in How do I hide the window title bar from QTabWidget:

        setWindowFlags(Qt::Window | Qt::FramelessWindowHint);

        The title bar when the tabwidget in within the main window.

        alt text

        M 1 Reply Last reply 5 Jul 2020, 15:04
        1
        • L lansing
          5 Jul 2020, 14:58

          @mrjj said in How do I hide the window title bar from QTabWidget:

          setWindowFlags(Qt::Window | Qt::FramelessWindowHint);

          The title bar when the tabwidget in within the main window.

          alt text

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 5 Jul 2020, 15:04 last edited by
          #4

          @lansing
          Hi That seems to be a QDockWidget title bar ?

          If Yes to that , try
          dockWidget->setTitleBarWidget(new QWidget(dockWidget));

          L 1 Reply Last reply 5 Jul 2020, 15:11
          0
          • M mrjj
            5 Jul 2020, 15:04

            @lansing
            Hi That seems to be a QDockWidget title bar ?

            If Yes to that , try
            dockWidget->setTitleBarWidget(new QWidget(dockWidget));

            L Offline
            L Offline
            lansing
            wrote on 5 Jul 2020, 15:11 last edited by
            #5

            @mrjj

            It hided the bar, but I lost the docking ability.

            M 1 Reply Last reply 5 Jul 2020, 15:13
            1
            • L lansing
              5 Jul 2020, 15:11

              @mrjj

              It hided the bar, but I lost the docking ability.

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 5 Jul 2020, 15:13 last edited by
              #6

              @lansing
              Did you try to dock it from code then ?

              L 1 Reply Last reply 5 Jul 2020, 15:32
              0
              • M mrjj
                5 Jul 2020, 15:13

                @lansing
                Did you try to dock it from code then ?

                L Offline
                L Offline
                lansing
                wrote on 5 Jul 2020, 15:32 last edited by
                #7

                @mrjj

                I don't know how to do it, couldn't find any example.

                M 1 Reply Last reply 5 Jul 2020, 15:45
                0
                • L lansing
                  5 Jul 2020, 15:32

                  @mrjj

                  I don't know how to do it, couldn't find any example.

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 5 Jul 2020, 15:45 last edited by
                  #8

                  @lansing
                  Hi
                  Do you read the docs?
                  https://doc.qt.io/qt-5/qdockwidget.html
                  Its always a good idea to skim over what features a class has.

                  Anyway, its
                  setFloating(false);
                  https://doc.qt.io/qt-5/qdockwidget.html#floating-prop

                  L 1 Reply Last reply 5 Jul 2020, 16:02
                  1
                  • M mrjj
                    5 Jul 2020, 15:45

                    @lansing
                    Hi
                    Do you read the docs?
                    https://doc.qt.io/qt-5/qdockwidget.html
                    Its always a good idea to skim over what features a class has.

                    Anyway, its
                    setFloating(false);
                    https://doc.qt.io/qt-5/qdockwidget.html#floating-prop

                    L Offline
                    L Offline
                    lansing
                    wrote on 5 Jul 2020, 16:02 last edited by
                    #9

                    @mrjj

                    Yes I looked at that doc for over 10 minutes and I couldn't find it. There's nothing about dragging and moving the widget when the title bar was hidden.

                    This doesn't make the dockwidget draggable.

                    m_ui->myDockWidget->setTitleBarWidget(new QWidget(m_ui->myDockWidget));
                    m_ui->myDockWidget->setFloating(false);
                    
                    M 1 Reply Last reply 5 Jul 2020, 16:09
                    0
                    • L lansing
                      5 Jul 2020, 16:02

                      @mrjj

                      Yes I looked at that doc for over 10 minutes and I couldn't find it. There's nothing about dragging and moving the widget when the title bar was hidden.

                      This doesn't make the dockwidget draggable.

                      m_ui->myDockWidget->setTitleBarWidget(new QWidget(m_ui->myDockWidget));
                      m_ui->myDockWidget->setFloating(false);
                      
                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 5 Jul 2020, 16:09 last edited by
                      #10

                      @lansing

                      Well it uses the title bar for dragging and you remove it so im not sure why you expect that to still work ?

                      But you can fix it with
                      https://stackoverflow.com/questions/18765918/how-to-create-a-draggable-borderless-and-titleless-top-level-window-in-qt

                      But why not just leave it alone if you want all the features it provides?

                      Maybe you could hide it when it get docked but then you cannot undock it again.

                      So not really sure what you really want as you cant both remove it and use it :=)

                      1 Reply Last reply
                      0
                      • T Offline
                        T Offline
                        tIk90wT
                        wrote on 5 Jul 2020, 16:10 last edited by tIk90wT 7 May 2020, 16:37
                        #11

                        If you only need it hide it from visibility, you could try to use the stylesheet to set dock widget title as the same color as the background. Customize dock widget. I'll post some pyside2 code to show what I mean.....

                        1 Reply Last reply
                        1
                        • T Offline
                          T Offline
                          tIk90wT
                          wrote on 5 Jul 2020, 16:48 last edited by
                          #12

                          I'm not able to reproduce the title bar as shown in this picture without knowing your code. picture. By default, I get no background. But here is the code

                          import sys
                          from PySide2.QtWidgets import QMainWindow, QWidget, QLabel, QDockWidget, QTabWidget, QApplication
                          
                          
                          class MainWindow(QMainWindow):
                              def __init__(self):
                                  super(MainWindow, self).__init__()
                          
                                  self.t1 = QLabel("tab 1")
                                  self.t2 = QLabel("tab 2")
                                  self.tabWidget = QTabWidget()
                                  self.tabWidget.addTab(self.t1, "Tab 1")
                                  self.tabWidget.addTab(self.t2, "Tab 2")
                          
                                  self.dockWidget = QDockWidget()
                                  self.dockWidget.setWidget(self.tabWidget)
                          
                                  self.dockWidget.setStyleSheet("QDockWidget:title {background-color: none;}")
                          
                                  self.setCentralWidget(self.dockWidget)
                          
                          
                          if __name__ == '__main__':
                              app = QApplication(sys.argv)
                              mw = MainWindow()
                              mw.show()
                              sys.exit(app.exec_())
                          
                          L 1 Reply Last reply 5 Jul 2020, 17:51
                          1
                          • T tIk90wT
                            5 Jul 2020, 16:48

                            I'm not able to reproduce the title bar as shown in this picture without knowing your code. picture. By default, I get no background. But here is the code

                            import sys
                            from PySide2.QtWidgets import QMainWindow, QWidget, QLabel, QDockWidget, QTabWidget, QApplication
                            
                            
                            class MainWindow(QMainWindow):
                                def __init__(self):
                                    super(MainWindow, self).__init__()
                            
                                    self.t1 = QLabel("tab 1")
                                    self.t2 = QLabel("tab 2")
                                    self.tabWidget = QTabWidget()
                                    self.tabWidget.addTab(self.t1, "Tab 1")
                                    self.tabWidget.addTab(self.t2, "Tab 2")
                            
                                    self.dockWidget = QDockWidget()
                                    self.dockWidget.setWidget(self.tabWidget)
                            
                                    self.dockWidget.setStyleSheet("QDockWidget:title {background-color: none;}")
                            
                                    self.setCentralWidget(self.dockWidget)
                            
                            
                            if __name__ == '__main__':
                                app = QApplication(sys.argv)
                                mw = MainWindow()
                                mw.show()
                                sys.exit(app.exec_())
                            
                            L Offline
                            L Offline
                            lansing
                            wrote on 5 Jul 2020, 17:51 last edited by
                            #13

                            @tIk90wT said in How do I hide the window title bar from QTabWidget:

                            QDockWidget:title

                            Thanks, I also added border: 0px in the style and the window bar is gone.

                            alt text

                            However it looks weird with blank space on top and the control is uncomfortable, I missed a few time on my dragging because I missed clicking in the title areas.

                            M 1 Reply Last reply 5 Jul 2020, 17:59
                            0
                            • L lansing
                              5 Jul 2020, 17:51

                              @tIk90wT said in How do I hide the window title bar from QTabWidget:

                              QDockWidget:title

                              Thanks, I also added border: 0px in the style and the window bar is gone.

                              alt text

                              However it looks weird with blank space on top and the control is uncomfortable, I missed a few time on my dragging because I missed clicking in the title areas.

                              M Offline
                              M Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on 5 Jul 2020, 17:59 last edited by
                              #14

                              @lansing
                              Yep from a UX standpoint its just confusing.

                              L 1 Reply Last reply 5 Jul 2020, 18:13
                              0
                              • M mrjj
                                5 Jul 2020, 17:59

                                @lansing
                                Yep from a UX standpoint its just confusing.

                                L Offline
                                L Offline
                                lansing
                                wrote on 5 Jul 2020, 18:13 last edited by
                                #15

                                @mrjj

                                I tired to move the dockWidgetContents up to make it looks better. I set the geometry of the starting y axis to negative, but it's not having any effect.

                                m_ui->dockWidgetContents ->setGeometry(0, -50,
                                         m_ui->dockWidgetContents ->width(), m_ui->dockWidgetContents ->height());
                                
                                
                                M 1 Reply Last reply 5 Jul 2020, 18:15
                                0
                                • L lansing
                                  5 Jul 2020, 18:13

                                  @mrjj

                                  I tired to move the dockWidgetContents up to make it looks better. I set the geometry of the starting y axis to negative, but it's not having any effect.

                                  m_ui->dockWidgetContents ->setGeometry(0, -50,
                                           m_ui->dockWidgetContents ->width(), m_ui->dockWidgetContents ->height());
                                  
                                  
                                  M Offline
                                  M Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on 5 Jul 2020, 18:15 last edited by mrjj 7 May 2020, 18:18
                                  #16

                                  @lansing
                                  Do you use a layout inside ?
                                  that space on top kinda fits with a layout default content margins.

                                  L 1 Reply Last reply 5 Jul 2020, 18:26
                                  1
                                  • M mrjj
                                    5 Jul 2020, 18:15

                                    @lansing
                                    Do you use a layout inside ?
                                    that space on top kinda fits with a layout default content margins.

                                    L Offline
                                    L Offline
                                    lansing
                                    wrote on 5 Jul 2020, 18:26 last edited by
                                    #17

                                    @mrjj

                                    My doctwidget layout

                                    QDockWidget
                                    ----dockWidgetContents (vertical layout)
                                    --------QTabWidget
                                    ------------QTextEdit
                                    --------QTextEdit
                                    

                                    The dockWidgetContents is the layout of the dockWidget.

                                    M 1 Reply Last reply 5 Jul 2020, 18:28
                                    0
                                    • L lansing
                                      5 Jul 2020, 18:26

                                      @mrjj

                                      My doctwidget layout

                                      QDockWidget
                                      ----dockWidgetContents (vertical layout)
                                      --------QTabWidget
                                      ------------QTextEdit
                                      --------QTextEdit
                                      

                                      The dockWidgetContents is the layout of the dockWidget.

                                      M Offline
                                      M Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on 5 Jul 2020, 18:28 last edited by mrjj 7 May 2020, 18:28
                                      #18

                                      Ok
                                      so on the vertical layout, set its margins to zero and see. default its 12 pixels.
                                      Im not sure if that is the case but it could explain the huge gap.
                                      setContentsMargins(0,0,0,0);

                                      L 1 Reply Last reply 5 Jul 2020, 18:47
                                      1
                                      • M mrjj
                                        5 Jul 2020, 18:28

                                        Ok
                                        so on the vertical layout, set its margins to zero and see. default its 12 pixels.
                                        Im not sure if that is the case but it could explain the huge gap.
                                        setContentsMargins(0,0,0,0);

                                        L Offline
                                        L Offline
                                        lansing
                                        wrote on 5 Jul 2020, 18:47 last edited by
                                        #19

                                        @mrjj

                                        The top gap does become smaller, but when docked, I still couldn't move the contents into the title bar area.

                                        alt text

                                        M 1 Reply Last reply 5 Jul 2020, 19:09
                                        0
                                        • L lansing
                                          5 Jul 2020, 18:47

                                          @mrjj

                                          The top gap does become smaller, but when docked, I still couldn't move the contents into the title bar area.

                                          alt text

                                          M Offline
                                          M Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on 5 Jul 2020, 19:09 last edited by
                                          #20

                                          @lansing
                                          Well when a widget is in a layout its not possible to move it.

                                          you could try to use
                                          https://doc.qt.io/qt-5/qdockwidget.html#titleBarWidget
                                          and then setFixedHeight(1);
                                          and see if that changes anything.

                                          L 1 Reply Last reply 5 Jul 2020, 19:17
                                          1

                                          2/34

                                          5 Jul 2020, 14:39

                                          32 unread
                                          • Login

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