简体   繁体   中英

Python/PySide: How to make a widget that will stay on top of the main window, but not cover up other widgets?

So I have a script running inside another program (The Foundry's Hiero) and I'm just making a new QWidget object, and calling self.show()

Now, I can set it to self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) , so my window will stay on top of the main window, even if you click on something in the main window.

The problem is, this is a sort of popup window that you configure settings in, and it triggers other QWidget popups. If I set my window to WindowStaysOnTopHint , those subdialogs that my widget triggers end up beneath my widget.

Is there a way in PySide/PyQt to make a window stay on top/keep focus from the main application window in particular, but not everything ?

You can use the QApplication.focusChanged signal to raise your widget up when Hiero's main window is selected. Then you would just need to remove the WindowStaysOnTopHint flag.

I'm not familiar with Hiero's API, but I'm guessing you could try something like:

def raiseMyWidget(old, new):
    if new == hiero.ui.mainWindow():
        myWidget.raise_()
QtWidgets.QApplication.instance().focusChanged.connect(raiseMyWidget)

Hope this helps. You can take advantage of the old parameter or some other means to make sure that your widget isn't raised above the others as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM