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

thefog picture thefog · Nov 18, 2014 · Viewed 7.7k times · Source

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

Answer

Yoann Quenach de Quivillic picture Yoann Quenach de Quivillic · Nov 18, 2014

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!