I have a QMainWindow with a main "display" widget, and several minor widgets. I'd like the ability to toggle the minor widgets on/off when the mouse enters or leaves the window.
I can achieve this basic functionality by implementing enterEvent
and leaveEvent
with calls to show/hiding for the unessential widgets. However, Qt4's default behavior is to leave the QMainWindow geometry fixed, and resize the important widget. I would rather maintain the geometry of this widget, and move/resize the QMainWindow as necessary. Is this possible?
Here's a simplified example in PyQt4
from PyQt4.QtGui import *
from PyQt4.QtCore import *
app = QApplication([''])
class MyWidget(QWidget):
def __init__(self, parent=None):
super(MyWidget, self).__init__(parent)
layout = QVBoxLayout()
self.setLayout(layout)
self.main = QPushButton("major")
self.main.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.minor = QPushButton("minor")
layout.addWidget(self.main)
layout.addWidget(self.minor)
def enterEvent(self, event):
self.minor.show()
def leaveEvent(self, event):
self.minor.hide()
mw = QMainWindow()
mw.setCentralWidget(MyWidget())
mw.show()
app.exec_()
Instead of the "major" button growing/shrinking, I would like the boundaries of MyWidget to change to wrap around this button.