How do I hide the window title bar from QDockWidget
-
@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 -
@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-propwrote on 5 Jul 2020, 16:02 last edited byYes 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);
-
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);
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-qtBut 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 :=)
-
wrote on 5 Jul 2020, 16:10 last edited by tIk90wT 7 May 2020, 16:37
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.....
-
wrote on 5 Jul 2020, 16:48 last edited by
I'm not able to reproduce the title bar as shown in this picture without knowing your code.
. 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_())
-
I'm not able to reproduce the title bar as shown in this picture without knowing your code.
. 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_())
wrote on 5 Jul 2020, 17:51 last edited by@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.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.
-
@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.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.
@lansing
Yep from a UX standpoint its just confusing. -
wrote on 5 Jul 2020, 18:13 last edited by
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());
-
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());
Lifetime Qt Championwrote on 5 Jul 2020, 18:15 last edited by mrjj 7 May 2020, 18:18@lansing
Do you use a layout inside ?
that space on top kinda fits with a layout default content margins. -
@lansing
Do you use a layout inside ?
that space on top kinda fits with a layout default content margins. -
My doctwidget layout
QDockWidget ----dockWidgetContents (vertical layout) --------QTabWidget ------------QTextEdit --------QTextEdit
The
dockWidgetContents
is the layout of the dockWidget.Lifetime Qt Championwrote on 5 Jul 2020, 18:28 last edited by mrjj 7 May 2020, 18:28Ok
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); -
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); -
The top gap does become smaller, but when docked, I still couldn't move the contents into the title bar area.
@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. -
@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. -
@lansing
Yes that was expected.
But did it accept smaller size ? -
My program crashed on run
QWidget * titleBar = m_ui->myrDockWidget->titleBarWidget(); titleBar->setFixedHeight(1);
Lifetime Qt Championwrote on 5 Jul 2020, 19:29 last edited by mrjj 7 May 2020, 19:30@lansing
ah sorry my bad
Docs says
"Returns the custom title bar widget set on the QDockWidget, or nullptr if no custom title bar has been set."but we didnt anymore so its null. ok so not an option unless we do
m_ui->myDockWidget->setTitleBarWidget(new QWidget(m_ui->myDockWidget));But you are right. Its too hard to hit if smaller so guess we just have to leave it.
I just wonder where that space comes from as the examples don't have it.
-
@lansing
ah sorry my bad
Docs says
"Returns the custom title bar widget set on the QDockWidget, or nullptr if no custom title bar has been set."but we didnt anymore so its null. ok so not an option unless we do
m_ui->myDockWidget->setTitleBarWidget(new QWidget(m_ui->myDockWidget));But you are right. Its too hard to hit if smaller so guess we just have to leave it.
I just wonder where that space comes from as the examples don't have it.
wrote on 5 Jul 2020, 19:33 last edited by Bonnie 7 May 2020, 19:33@mrjj said in How do I hide the window title bar from QTabWidget:
I just wonder where that space comes from as the examples don't have it.
That must be the layout default margins...The OP mentioned using a vertical layout...
-
@mrjj said in How do I hide the window title bar from QTabWidget:
I just wonder where that space comes from as the examples don't have it.
That must be the layout default margins...The OP mentioned using a vertical layout...
Lifetime Qt Championwrote on 5 Jul 2020, 19:33 last edited by mrjj 7 May 2020, 19:35@Bonnie
Also my thought but we did try
setContentsMargins(0,0,0,0);
higher up.So maybe that space is really just the hidden titlebar, it just look bigger to me than the samples.
16/34