Truncated menus on Windows on first open on some PyQt versions, but not all

Marko Luther <[email protected]>
Newsgroups gmane.comp.python.pyqt-pykde
Message-ID <[email protected]>
Dear all,

we observed a strange issue where the application menus (only) on Windows got truncated on first opening after the application start in our application. It seems that the menus did not get properly initialised. We traced this down to our use of the QGraphicsDropShadowEffect for buttons on the main window.

btn.setGraphicsEffect(QtWidgets.QGraphicsDropShadowEffect)

Interestingly this issue only shows up in some versions, but not others (all installed via pip).
- menus are initially truncated on PyQt 5.12, PyQt 5.12.1, PyQt 5.12.2 and PyQt 5.13
- menus work as expected in PyQt 5.11.3 or PyQt 5.12.3

We tested this under Windows 7, 8, and 10. So the version of Windows might not be relevant.

Are we doing something wrong here, or is this a Qt/PyQt (build-)issue on some versions?
We couldn't find a corresponding Qt issue on the Qt issue tracker.

A short example script that reveals the issue is attached below as well as two screen shot from running it on PyQt 5.12.2. Note that the issue not only happens in combination with a keyboard shortcuts and comes with some variations depending on the app menu language used. On our Chinese menus, submenus are not only truncated, but also rendered with some spacing between the main menu and the submenu.

Thanks for your support,
Marko

_______________________________________________
PyQt mailing list    [email protected]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
truncatedmenu.py (text/x-python-script, 1.1 KB)
import sys
from PyQt5 import QtGui, QtCore, QtWidgets

class Window(QtWidgets.QMainWindow):


    def __init__(self):

        super(Window, self).__init__()
        self.setGeometry(50, 50, 400, 200)

        closeAction = QtWidgets.QAction("Is truncated if no shortcut", self)
        closeAction.setShortcut("Ctrl+Q")
        closeAction.triggered.connect(self.close_application)

        mainMenu = self.menuBar()
        fileMenu = mainMenu.addMenu('&File')
        fileMenu.addAction(closeAction)
        
        self.home()


    def home(self):
        btn = QtWidgets.QPushButton("Quit", self)
        btn.clicked.connect(self.close_application)
        btn.resize(btn.minimumSizeHint())
        btn.move(0,75)

        #Comment this line to prevent menu truncating on the first access
        btn.setGraphicsEffect(QtWidgets.QGraphicsDropShadowEffect(self))
        
        self.show()

    def close_application(self):
        sys.exit()


def run():
    app = QtWidgets.QApplication(sys.argv)
    GUI = Window()
    sys.exit(app.exec_())


run()
first-click.png (image/png, 50.5 KB) - not displayed
second-click.png (image/png, 42.9 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.