You can center a window in PySide6 by using the QDesktopWidget
class to get the size of the screen and then centering your window on it.
Here's an example:
from PySide6.QtGui import QDesktopWidget
from PySide6.QtWidgets import QApplication, QMainWindow
app = QApplication([])
window = QMainWindow()
# Set window dimensions
window.resize(800, 600)
# Center window on screen
desktop = QDesktopWidget()
rect = desktop.availableGeometry(desktop.primaryScreen())
x = int((rect.width() - window.width()) / 2)
y = int((rect.height() - window.height()) / 2)
window.move(x, y)
window.show()
app.exec_()
This should work regardless of whether you're using QT, QML, or WSL2.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-13 10:56:07 +0000
Seen: 11 times
Last updated: Jun 13 '23
What is the method for aligning an image at the center using NPOI in c#?
What is the method for placing an element at the center below its preceding sibling element?
How do I position the Widget in the middle of the body using tabBarView()?
What is the correct method of aligning PIL text to the center?
What is the method to center a div vertically?
What is the process for creating a circle using osgEarth::CircleNode?
How can a tangent line be drawn from a specified point to a circle using OpenCV?