simplest script: its just show context menu with 2 elements after running but first QMenu initializing is more slowly when i expected 0_o
it seems Qt to be not optimized for such a usage scenario?
after run script:
- Main Window show immediately
- but context menu show after ~0.7-1.2 sec after running
it's not a problem for me, but i'm just wondering - why is reason that behaviour of Qt and ways to improve perf if it possible
- perf_counter() show, that all script processes ( until -> menu.exec(QCursor.pos()) ) executed by 0.06-0.09 sec
- i compiled script by "Nuitka", but speed is the same
- on windows os i have "autohotkey" script, and it run custom context menu instantly
- run platform windows 10 18362 64x
- python 3.10.4 virtual env not use
- run script *.pyw without console output
differ codes i trial - result is similar this is one of:
import sys
from PyQt5.QtGui import QCursor
from PyQt5.QtWidgets import (QAction, QMenu, QApplication)
"""
for Qt6:
from PyQt6.QtGui import QCursor, QAction
from PyQt6.QtWidgets import (QMenu, QApplication)
"""
def context_menu():
menu = QMenu()
action1 = QAction("Exit option")
action1.triggered.connect(lambda: sys.exit())
action2 = QAction("Second option")
action2.triggered.connect(lambda: print("You have clicked the second option"))
menu.addAction(action1)
menu.addAction(action2)
sys.exit(menu.exec(QCursor.pos()))
app = QApplication([])
context_menu()