QToolButton menu is stuck on the main screen, while application is on second screen.
Solved
Qt for Python
-
Hello.
I'm using two monitors. I notice that when my application is on second screen and I click on QToolButton which contains menu, menu shows on main screen. I tried many things to prevent this but i failed.
PyQt5=5.15.0
Does anyone have idea how to fix this?
I found that someone reported the issue for c++ QTBUG-85012.
import sys from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QApplication, QMainWindow, QToolButton, QStyle, QWidget, QMenu, QAction if __name__ == '__main__': app = QApplication([]) window = QMainWindow() window.setMinimumSize(600, 400) window.setCentralWidget(QWidget()) toolbar = window.addToolBar("tool") tool_button = QToolButton(toolbar) tool_button.setText("Tool button.") tool_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) tool_button.setIcon(window.style().standardIcon(QStyle.SP_DialogApplyButton)) menu = QMenu(window) first_action = QAction(window.style().standardIcon(QStyle.SP_ArrowRight), "Option_1", ) first_action.triggered.connect(lambda: print("Option_1")) second_action = QAction(window.style().standardIcon(QStyle.SP_ArrowLeft), "Option_2") second_action.triggered.connect(lambda: print("Option_2")) menu.addAction(first_action) menu.addAction(second_action) tool_button.setMenu(menu) tool_button.setPopupMode(QToolButton.InstantPopup) toolbar.addWidget(tool_button) toolbar.setMovable(False) toolbar.setFloatable(False) window.show() sys.exit(app.exec_())
-
Hi and welcome to devnet,
Base on the report, it seems to be a regression so it looks like you should use Qt 5.14.2.
-
@SGaist said in QToolButton menu is stuck on the main screen, while application is on second screen.:
Hi and welcome to devnet,
Base on the report, it seems to be a regression so it looks like you should use Qt 5.14.2.
Thanks for answer, It's working.