Get incorrect widget size by window handle
-
@Tim-Tu
What's is returned byyourWidget->windowHandle()->handle()->frameMargins()
? -
@Axel-Spoerl said in Get incorrect widget size by window handle:
What's is returned by yourWidget->windowHandle()->handle()->frameMargins()?
There is some thing wrong:
print(self.windowHandle().Handle()) AttributeError: 'PySide6.QtGui.QWindow' object has no attribute 'Handle'
Did you means
contentsMargins
?
I have changed the test code:##Author github user @Tanneguydv, 2021 import os import sys from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox from PySide6.QtWidgets import ( QApplication, QWidget, QVBoxLayout ) from OCC.Display.backend import load_backend load_backend("qt-pyside6") import OCC.Display.qtDisplay as qtDisplay class App(QWidget): def __init__(self): super().__init__() self.title = "PyQt5 / pythonOCC" self.left = 300 self.top = 300 self.width = 800 self.height = 300 self.initUI() def initUI(self): self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.lay = QVBoxLayout() self.setLayout(self.lay) self.canvas = qtDisplay.qtViewer3d(self) self.lay.addWidget(self.canvas) self.canvas.InitDriver() self.display = self.canvas._display a_box = BRepPrimAPI_MakeBox(10.0, 20.0, 30.0).Shape() self.ais_box = self.display.DisplayShape(a_box)[0] self.display.FitAll() self.show() self.canvas.InitDriver() print(self.size()) print(self.canvas.size()) print(self.contentsMargins()) print(self.canvas.contentsMargins()) if __name__ == "__main__": app = QApplication(sys.argv) ex = App() sys.exit(app.exec_())
The result:
Xw_Window created. Display3d class successfully initialized. ######################################### OpenGl information: GLvendor: AMD GLdevice: AMD Radeon Graphics (rembrandt, LLVM 15.0.7, DRM 3.52, 6.4.8-arch1-1) GLversion: 4.6 (Compatibility Profile) Mesa 23.1.5 GLSLversion: 4.60 Max texture size: 16384 Max FBO dump size: 16384x16384 Max combined texture units: 192 Max MSAA samples: 8 Viewport: 810x290 Window buffer: RGB8 ALPHA8 DEPTH24 STENCIL8 ResolutionRatio: 1 FBO buffer: GL_SRGB8_ALPHA8 GL_DEPTH24_STENCIL8 PySide6.QtCore.QSize(800, 300) PySide6.QtCore.QSize(778, 278) <PySide6.QtCore.QMargins(0, 0, 0, 0) at 0x7f5581c95ec0> <PySide6.QtCore.QMargins(0, 0, 0, 0) at 0x7f5581c95ec0>
-
There is some thing wrong:
print(self.windowHandle().Handle())
AttributeError: 'PySide6.QtGui.QWindow' object has no attribute 'Handle'handle()
, notHandle()
. -
@Axel-Spoerl
Sorry, but there still has no attributeprint(self.windowHandle().handle()) AttributeError: 'PySide6.QtGui.QWindow' object has no attribute 'handle'
-
@Axel-Spoerl
QWindow Class shows no sign of a (public at least, from C++, let alone Python)handle()
method? -
@JonB
Hm, qwindow.cpp:2050-2070:/*! Returns the platform window corresponding to the window. \internal */ QPlatformWindow *QWindow::handle() const { Q_D(const QWindow); return d->platformWindow; }
But...wait: It's a public method, documented as internal. That's why it doesn't show up in the documentation and maybe also not in python.
-
@Axel-Spoerl
:) And is itpublic
? If so, either it's not documented, or maybe because of that it didn't get added into PySide/PyQt (since the OP shows it not working from Python)? The comment shows\internal
....And it returns a
QPlatformWindow
, which does not seem to be documented either, so maybe that's why it's not provided?? [It seems to have been mentioned in Qt 4.8 but not since then? :) ] -
@JonB
Messages crossed ;-)
It's indeedpublic
.
QPlatformWindow
also isn't documented and probably not available in PySide/PyQt.
Thanks, Jon, for the hint. -
@Axel-Spoerl said in Get incorrect widget size by window handle:
It's indeed
public
.I just added to my previous: The comment shows
\internal
.... -
Nontheless, to conclude this thread somehow:
FramlessWindowHint
is a hint and doesn't guarantee that window is really rendered frameless.
Native handles seem to get rendered in the case at hand. The pixel difference represents their size.
Given that my proposed way to confirm it doesn't work out in Python, looking at the physical window on the screen is the only way to confirm.