![]() |
[PyQt] self.pos().x() and self.pos().x() always return -3,-30 on PyQT5 - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [PyQt] self.pos().x() and self.pos().x() always return -3,-30 on PyQT5 (/thread-39179.html) |
self.pos().x() and self.pos().x() always return -3,-30 on PyQT5 - DrakeSoft - Jan-13-2023 Hi, I am using the code below to experiment with window size and psoition. I notice that irrespective of where I move the window self.pos().x() and self.pos().x() always return -3,-30 Is this a bug? I am running this on Ubuntu 22.04 import sys from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QTextEdit, QPushButton) class MainWindow(QMainWindow): def __init__(self): QMainWindow.__init__(self) self.resize(400, 200) centralWidget = QWidget() self.setCentralWidget(centralWidget) self.textEdit = QTextEdit() self.btn = QPushButton("get the screen position of `QMainWindow`") self.btn.clicked.connect(self.btnClicked) layoutV = QVBoxLayout(centralWidget) layoutV.addWidget(self.textEdit) layoutV.addWidget(self.btn) self.textEdit.append("Start:") self.textEdit.append("pos.x=`{}`, pos.y=`{}`" "".format(self.pos().x(), self.pos().y())) self.textEdit.append("geometry.x=`{}`, geometry.y=`{}`" "".format(self.geometry().x(), self.geometry().y())) self.textEdit.append("--------------------------------------") def btnClicked(self): self.textEdit.append("pos.x=`{}`, pos.y=`{}`" "".format(self.pos().x(), self.pos().y())) self.textEdit.append("geometry.x=`{}`, geometry.y=`{}`" "".format(self.geometry().x(), self.geometry().y())) def moveEvent(self, event): # QMoveEvent print("x=`{}`, y=`{}`".format(event.pos().x(), event.pos().y())) super(MainWindow, self).moveEvent(event) def resizeEvent(self, event): # QResizeEvent print("w=`{}`, h=`{}`".format( event.size().width(), event.size().height())) super(MainWindow, self).resizeEvent(event) app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_()) RE: self.pos().x() and self.pos().x() always return -3,-30 on PyQT5 - Axel_Erfurt - Jan-13-2023 Works fine in LMDE5 PyQt5 5.15.7
RE: self.pos().x() and self.pos().x() always return -3,-30 on PyQT5 - deanhystad - Jan-13-2023 Moving the window does not appear to send a Move event. Changing window focus does send a Move event (or something that gets mapped to a QWidget.moveEvent. Resize events work as expected. My guess is this is an attribute of the ubuntu window manager. I am running the default desktop (Think it is GNOME. Shows up as ubuntu.desktop). You could install a different desktop and see if it fixes your problem. RE: self.pos().x() and self.pos().x() always return -3,-30 on PyQT5 - DrakeSoft - Jan-15-2023 Thank you for your replies. The problem only occurs when running on wayland, so I think the issue is at that level rather than the window manager level. if I switch to X11 then self.pos().x(), self.pos().y() return the expected positions. I probably switched to wayland after upgrading from 20.04 to 22.04 and I do remember at that time beginning to see a lot of Wayland warnings. |