How to disable/hide the Close button in a pyQt QDockWidget

9.9k views Asked by At

Im trying to disable the close 'x' button, and I assumed that it would work by setting the DockWidgetFeature to only movable and floatable.

def CreateDockWidget (self):

    Pane = QtGui.QDockWidget()
    Pane.DockWidgetFeatures =  QtGui.QDockWidget.DockWidgetFloatable | QtGui.QDockWidget.DockWidgetMovable;
    Pane.setAllowedAreas( QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea )
    textBox1 = QtGui.QTextEdit()
    Pane.setWidget(textBox1 )
    self.addDockWidget( QtCore.Qt.LeftDockWidgetArea, Pane )

Why doesn't the above work ? BTW, if I don't set floatable, it remains floatable until its undockable (floating) then I can't re-dock it. Why is that ?

thanks

1

There are 1 answers

0
Yoann Quenach de Quivillic On BEST ANSWER

You were right, but you didn't actually set the features of your DockWidget. Call

Pane.setFeatures(QtGui.QDockWidget.DockWidgetFloatable | 
                 QtGui.QDockWidget.DockWidgetMovable)

instead of erasing DockWidgetFeatures with the assignment and you should be fine!