it haunts me for eons, mainly because of how many combinations of methodologies exist to move widgets and much more. Essentially, I have a simple widget that I would like to pop up in certain areas of my application. The problem is that I can never make her float to where I want her. In addition, I would like to set it up so that I can adjust its “pointer” based on whether it appears to point to the widget in the upper left corner of the application, and, say, to the right.
Ideally, I could place the popup almost next to the edges of the parent widget and snap it based on where it is. Here is what I tried.
from PyQt4.QtCore import * from PyQt4.QtGui import * import sys class popup(QWidget): def __init__(self, parent = None, widget=None): QWidget.__init__(self, parent) layout = QGridLayout(self) button = QPushButton("Very Interesting Text Popup. Here an arrow ^") layout.addWidget(button) self.move(widget.rect().bottomLeft()) class Window(QWidget): def __init__(self): QWidget.__init__(self) self.button = QPushButton('Hit this button to show a popup', self) self.button.clicked.connect(self.handleOpenDialog) self.button.move(250, 50) self.resize(600, 200) def handleOpenDialog(self): self.popup = popup(self, self.button) self.popup.show() if __name__ == '__main__': app = QApplication(sys.argv) win = Window() win.show() sys.exit(app.exec_())
This code generates a button that is randomly located in the middle of the widget. What I'm trying to get in this example is a pop-up window that appears under the button with its “rotary” button in the upper right corner, so that the arrow in the pop-up button will point to the lower right corner of the widget. However, it appears in the upper left corner of the window. In all my mess with .move, .setGeometry, and playing with QRect, I can't figure it out for life. Great pleasure to someone who can lend a hand. Thanks!
source share