2

Iis there a way to "collapse" (roll up) a QDialog or QMainWindow to just it's title-bar?

The current solution is to use:

self.setMinimumHeight(0);
self.resize(self.width(), 1);

using a height of 0 i.e. self.resize(self.width(), 0);

causes the dialog/window/widget to disappear!

(There is no show(..) hide() close..() or whatever event issued, also the dialog is not being destroyed, just disappears.)

If the dialog is rolled-up to 1-pixel, the user can still re-size it manually to finally have only the title-bar (and some os-related frameborder, but content being not visible).

There are applications that can do this with any window but this should be a PyQt/Pyside only solution and it works, except that tiny little border..

(The idea is to basically mimic Softimages window-rollup for dialogs/tools, to preserve the dialog in a minimized (rolled up) state on the screen without having it to minimize to the bottom of the screen.)

NoDataDumpNoContribution
  • 10,591
  • 9
  • 64
  • 104
mayanoob
  • 21
  • 1

2 Answers2

1

You can do this with QMdiArea and its subwindows.

from PySide import QtGui

qt_app = QtGui.QApplication([])

mdiArea = QtGui.QMdiArea()

subWin= QtGui.QMdiSubWindow(mdiArea)
subWin.setWindowTitle('Zero-height window')

mainWindow = QtGui.QMainWindow()
mainWindow.setCentralWidget(mdiArea)
mainWindow.show()    
qt_app.exec_()

Screenshot with PySide in Windows 7

Resizing a QWidget to zero will cause it to disappear from the screen. This applies to QMdiSubWindow as well, but with no content it looks completely "collapsed" The flip side is it doesn't look exactly like a regular window either (though that probably varies with environment). Also, once the subwindow is populated with widgets, you will need to take care of resizing it yourself.

For this kind of UI, you may prefer something like QDockWidget, though it has the same issues with resizing.

Community
  • 1
  • 1
Lack
  • 1,625
  • 1
  • 17
  • 29
-1

You can prevent vertical resizing of the window by using a fixed height:

    self.setFixedHeight(1)
ekhumoro
  • 115,249
  • 20
  • 229
  • 336
  • 1
    @Trilarion. It fixes the issue mentioned in the question of the user being able to manually resize the window. Other than that, it solves the problem in exactly the same way that the OP does. So, not a perfect solution, but certainly an improvement. I don't think a perfect solution is possible *in general*, because not all styles allow a window to be shaded. The `QMdiSubWindow` performs some hackery that can force a window to shade properly, but I don't know whether that can be done with a top-level window (I would guess not - it's probably down to the window manager). – ekhumoro Jan 26 '15 at 20:41
  • Your comment is very good. I would add it to the answer. I don't think that a 1 pixel height really answers the question. Having a zero height is probably not achievable on a QDialog... – NoDataDumpNoContribution Jan 26 '15 at 21:07
  • @Trilarion. Thanks. I'm not that certain about how window shading works, though (especially on other platforms). Maybe I should have skipped the answer, and just left some comments, instead... – ekhumoro Jan 26 '15 at 21:23