Dialog Locations on Multiscreen app
-
I have an app which will use three screens. I'm testing with two. I need any of the standard dialogs to appear over the main ui. The file dialogs seem to do so. Dialogs, in particular the QDialogColor seem to not want to move outside the screen that is most top left. Even if I create a non-static instance and force a move. The sample code is a stripped-down example of the Dialog Example.
The picture shows the screen positioning on Windows 10. Main screen is "1" and Aux Screen is "2" in the Display settings. It shows where the color dialog and message dialog end up and how the File dialog which is I think native, ends up above the main ui.
import sys from textwrap import dedent from PySide6.QtCore import Qt, Slot from PySide6.QtGui import QPalette from PySide6.QtWidgets import (QApplication, QDialog, QColorDialog, QFileDialog, QFrame, QGridLayout, QLabel, QPushButton, QMessageBox, QToolBox, QVBoxLayout, QWidget) class Dialog(QDialog): def __init__(self, parent=None): super().__init__(parent) self._open_files_path = '' frame_style = QFrame.Sunken | QFrame.Panel self._color_label = QLabel() self._color_label.setFrameStyle(frame_style) self._color_button = QPushButton("QColorDialog.get&Color()") self._open_file_name_label = QLabel() self._open_file_name_label.setFrameStyle(frame_style) self._open_file_name_button = QPushButton("QFileDialog.get&OpenFileName()") self._critical_label = QLabel() self._critical_label.setFrameStyle(frame_style) self._critical_button = QPushButton("QMessageBox.critica&l()") self._color_button.clicked.connect(self.set_color) self._critical_button.clicked.connect(self.critical_message) self._open_file_name_button.clicked.connect(self.set_open_file_name) vertical_layout = QVBoxLayout(self) toolbox = QToolBox() vertical_layout.addWidget(toolbox) page = QWidget() layout = QGridLayout(page) layout.addWidget(self._color_button, 0, 0) layout.addWidget(self._color_label, 0, 1) toolbox.addItem(page, "Color Dialog") page = QWidget() layout = QGridLayout(page) layout.addWidget(self._open_file_name_button, 1, 0) layout.addWidget(self._open_file_name_label, 1, 1) toolbox.addItem(page, "File Dialog") page = QWidget() layout = QGridLayout(page) layout.addWidget(self._critical_button, 0, 0) layout.addWidget(self._critical_label, 0, 1) toolbox.addItem(page, "Message Boxes") self.setWindowTitle("Standard Dialogs") @Slot() def set_color(self): color = QColorDialog.getColor(Qt.green, self, "Select Color") if color.isValid(): self._color_label.setText(color.name()) self._color_label.setPalette(QPalette(color)) self._color_label.setAutoFillBackground(True) @Slot() def set_open_file_name(self): fileName, filtr = QFileDialog.getOpenFileName(self, "QFileDialog.getOpenFileName()", self._open_file_name_label.text(), "All Files (*);;Text Files (*.txt)", "") if fileName: self._open_file_name_label.setText(fileName) @Slot() def critical_message(self): m = dedent("""\ Activating the liquid oxygen stirring fans caused an explosion in one of the tanks. Liquid oxygen levels are getting low. This may jeopardize the moon landing mission.""") msg_box = QMessageBox(QMessageBox.Critical, "QMessageBox.critical()", "Houston, we have a problem", QMessageBox.Abort | QMessageBox.Retry | QMessageBox.Ignore, self) msg_box.setInformativeText(m) reply = msg_box.exec() if reply == QMessageBox.Abort: self._critical_label.setText("Abort") elif reply == QMessageBox.Retry: self._critical_label.setText("Retry") else: self._critical_label.setText("Ignore") if __name__ == '__main__': app = QApplication(sys.argv) dialog = Dialog() availableGeometry = dialog.screen().availableGeometry() dialog.resize(availableGeometry.width() / 3, availableGeometry.height() / 3) dialog.move((availableGeometry.width() - dialog.width()) / 2, (availableGeometry.height() - dialog.height()) / 2) sys.exit(dialog.exec())
-
Which Qt version is this? Could you please post the output of the qtdiag command line tool or the screen information shown in the https://doc.qt.io/qtforpython-6/examples/example_widgets_widgetsgallery.html example (bottom right/ choose text browser in the tool box), preferably in text form?
-
@friedemannkleint
This is with the second monitor plugged in. Windows doesn't seem to report multiple screens. A few months ago I tried using the screeninfo library and it also didn't report 2 screen.Python
3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:38:34) [MSC v.1936 64 bit (AMD64)]
Qt Build
Qt 6.5.2 (x86_64-little_endian-llp64 shared (dynamic) release build; by MSVC 2019) [limited API]
Operating System
Windows 10 Version 22H2
Screens
High DPI scale factor rounding policy: PassThrough
"\.\DISPLAY1" 1280x960-240-960 96DPI, DPR=1.0A while back I tired the screen info lib and got the same result. One monitor reported. I just tried it as a standalone app and it does report two monitors:
Screen Monitor(x=0, y=0, width=1366, height=768, width_mm=344, height_mm=194, name='\\.\DISPLAY1', is_primary=True):
Width: 1366 pixels
Height: 768 pixels
Position: 0x0
Aspect Ratio: 1.78Screen Monitor(x=-240, y=-960, width=1280, height=960, width_mm=339, height_mm=254, name='\\.\DISPLAY2', is_primary=False):
Width: 1280 pixels
Height: 960 pixels
Position: -240x-960
Aspect Ratio: 1.33import sys from screeninfo import get_monitors # Get all connected monitors monitors = get_monitors() # Print information about each monitor for monitor in monitors: print("Screen {}:".format(monitor)) print(" Width: {} pixels".format(monitor.width)) print(" Height: {} pixels".format(monitor.height)) print(" Position: {}x{}".format(monitor.x, monitor.y)) print(" Aspect Ratio: {:.2f}".format(monitor.width / monitor.height)) print()
-
Have you tried the current release (6.6.1)? Next, I would recommend writing a simple app that continuously prints QWidget.screen() to check if it somehow mistakenly reports the wrong screen when you move it to the edges.
-
@friedemannkleint Thanks! Let me try that. I think I recall that only one screen is reported by Qt but I should try the latest release. I can also make my own color dialog and see what that does for me. My app doesn't need all the flexibility in color selection.
-
@Improv-Jester Upgrading to 6.6.1 has fixed it! Thankyou for taking the time and for you sage advice.