I called the resize
-method of the modal QDialog. I expected this to not affect its always-on-top behaviour, but instead it is now possible to bring the parent window to the front again.
The parent window is still not accessible for interactions (in this case the X/C/Ctrl+Q keybinds) while the modal is open.
Why does this happen?
My window manager is a twm-derivative (ctwm-4.0.3) running on X11, and it does not happen on xfce4.
I press X to open the resized dialog, and press C to open the "normal" one.
Additionally, the issue is reproducible also if I am the one to manually resize the modal and then try to raise the parent above it, with some caveats outlined further below.
import sys
from PyQt5.QtCore import QSize
from PyQt5.QtWidgets import QApplication, QWidget, QShortcut, QDialog
class Dialog(QDialog):
def __init__(self, parent, resize):
super().__init__(parent)
self.setModal(True)
if resize:
self.setWindowTitle("Not on top")
self.setStyleSheet("QDialog {background: magenta}")
self.resize(QSize(600,600))
else:
self.setWindowTitle("Always on top")
self.setStyleSheet("QDialog {background: purple}")
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Parent window")
self.setStyleSheet("MainWindow {background: orange}")
shortcut = QShortcut("Ctrl+Q", self)
shortcut.activated.connect(self.close)
shortcut = QShortcut("X", self)
shortcut.activated.connect(self.show_resized_dialog)
shortcut = QShortcut("C", self)
shortcut.activated.connect(self.show_dialog)
self.show()
def show_resized_dialog(self):
dialog = Dialog(self, True)
dialog.show()
self.raise_()
def show_dialog(self):
dialog = Dialog(self, False)
dialog.show()
self.raise_()
if __name__ == '__main__':
app = QApplication(sys.argv)
mainwindow = MainWindow()
sys.exit(app.exec_())
From some additional experimenting, including commenting out all resize
and raise_
-calls from the code and then manually resizing the modal myself by hand, it seems the issue starts happening once the modal grows to a certain size. This size (width,height) appears extremely consistent, but does not appear to be a function solely of the width or solely the height.
For example, (width,height)=(300,300)
causes it, as does (300,299)
and (299,300)
-- but (299,299)
does not and neither does (300,298)
-- but (301,298)
does cause it.
(200,460)
causes it but (200,459)
does not -- and as a last example (800,100)
causes the issue while (100,800)
does not.