0

I am building an app with a gui in Pyqt5, and am trying to make it float above other windows, but it just won't work. I have tried setting other flags at the same time, but the only one that doesn't work is WindowStaysOnTopHint.

Here you have a simple example that I have been working with, FramelessWindowHint: fine, WindowStaysOnTopHint not working. I thought maybe this was a Linux thing, that it wouldn't enable it to be hard coded and had to be used through the menu of the window itself, but a similar program in Java works just fine, and the window stays on top.

from PyQt5 import QtGui, QtCore
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QSizeGrip
import sys
 
 
class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.title = "PyQt5 Size Grip"
        self.top = 200
        self.left = 500
        self.width = 640
        self.height = 480
        self.setWindowTitle(self.title)
        self.setWindowIcon(QtGui.QIcon("icon.png"))
        self.setGeometry(self.left, self.top, self.width, self.height)
        flags = QtCore.Qt.WindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint)
        self.setWindowFlags(flags)
        vboxlayout = QVBoxLayout()
        sizegrip = QSizeGrip(self)
        #sizegrip.setVisible(True)
        vboxlayout.addWidget(sizegrip)
        self.setLayout(vboxlayout)
        self.show()
 
 
 
if __name__ == "__main__":
    App = QApplication(sys.argv)
    window = Window()
    sys.exit(App.exec())

Any help here would be much appreciated, as this is a core feature and I would hate to have to rewrite this whole thing in Java :)

  • I got it working on two different Linux desktops, so it might be related to the wm you're using. Try by *adding* the flags instead of overwriting them: `self.setWindowFlags(self.windowFlags() | flags)`. Also, the size grip should be placed in a corner (add the alignment *keyword* argument to `addWidget()`, with a proper Qt alignment flag), and you should also not overwrite `self.width` and `self.height` with integer values, as they are actually member functions of all QWidgets, so use either a local variable or another name. – musicamante Dec 11 '21 at 16:46
  • You are correct indeed! I switched from Ubuntu Wayland to just Ubuntu and that seems to have fixed the issue. Thank you so much :) – Austin Sallow Dec 11 '21 at 17:26
  • See this related qtbug: https://bugreports.qt.io/browse/QTBUG-73456 – musicamante Dec 11 '21 at 17:47

0 Answers0