I hacked your example on Mac OS X using PySide. After spending quite a while, I found the following solution:
from PySide.QtGui import * from PySide.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 resizeEvent(self, event): self.appendix = self.minor.frameGeometry().height() + 2 if self.minor.isVisible(): self.varheight = mw.height() - self.appendix else: self.varheight = mw.height() def enterEvent(self, event): self.minor.show() mw.resize(mw.width(), self.varheight + self.appendix) def leaveEvent(self, event): self.minor.hide() mw.resize(mw.width(), self.varheight) mw = QMainWindow() mw.setCentralWidget(MyWidget()) mw.show() app.exec_()
This is not ideal since the initial state does not check the position of the mouse. Also, the magic "+ 2" should probably be widget geometry computable from some other metrics. But for example, this should be good.
To implement this task, it took several hours. It is imperative to make sure that all calculations are in a fixed state. Otherwise, the linking mechanism will produce difficult to understand results or even endless loops.
resizeEvent retrieves the correct values ββfrom the size of the widget, but nothing else. Then enterEvent and leaveEvent use these values ββand resize.
My variables are not initialized. You can do this, but the first resize happens earlier than other events.
source share