如何使修剪网格窗口在屏幕上居中?

问题描述 投票:0回答:1

我已经开始使用Python的

trimesh
包,我想做的第一件事就是设置图形窗口的大小及其在屏幕上的位置。

我弄清楚了如何调整图形窗口的大小,如下面的简单代码(来自 https://github.com/mikedh/trimesh/blob/main/examples/colors.ipynb)所示:

import trimesh

# The XAML file is found at https://github.com/mikedh/trimesh/blob/main/models/machinist.XAML
mesh = trimesh.load("machinist.XAML", process=False)
mesh.visual.kind
# Resolution is an undocumated argument - I had to figure it out myself
mesh.show(resolution=(600,600))

但我也想将网格窗口置于屏幕中央。有谁知道怎么办吗

python pyglet trimesh
1个回答
0
投票
import trimesh
import sys
from PyQt5 import QtWidgets, QtCore
from trimesh.viewer import windowed

# Load the mesh
mesh = trimesh.load("machinist.XAML", process=False)

# Create a QApplication (required for all PyQt5 applications)
app = QtWidgets.QApplication(sys.argv)

# Create a main window to hold the mesh viewer
main_window = QtWidgets.QMainWindow()

# Set the resolution of the mesh window
resolution = (600, 600)

# Calculate the center position of the screen
screen_geometry = QtWidgets.QDesktopWidget().availableGeometry()
x = (screen_geometry.width() - resolution[0]) // 2
y = (screen_geometry.height() - resolution[1]) // 2

# Set the size and position of the window
main_window.setGeometry(x, y, resolution[0], resolution[1])

# Create a trimesh viewer and set it as the central widget
mesh_viewer = windowed.SceneViewer(mesh, resolution=resolution)
main_window.setCentralWidget(mesh_viewer.window)

# Show the window
main_window.show()

# Start the application's event loop
sys.exit(app.exec_())
© www.soinside.com 2019 - 2024. All rights reserved.