这是我的代码
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.Display.OCCViewer import rgb_color
from OCC.Display.backend import load_backend,get_loaded_backend
load_backend("qt-pyside2")
import OCC.Display.qtDisplay as qtDisplay
import sys,os
class MainWindow(QMainWindow):
BORDER_WIDTH = 5
def __init__(self):
super().__init__()
self.main_widget = QWidget()
self.main_layout = QVBoxLayout()
self.main_widget.setLayout(self.main_layout)
self.setCentralWidget(self.main_widget)
self.canvas = qtDisplay.qtViewer3d(self)
self.canvas.InitDriver()
self.main_layout.addWidget(self.canvas)
self.setWindowFlags(Qt.CustomizeWindowHint)
QCoreApplication.instance().installEventFilter(self)
self._isResizeEnabled = True
def eventFilter(self, obj, event):
et = event.type()
if et != QEvent.MouseButtonPress and et != QEvent.MouseMove or not self._isResizeEnabled:
return False
edges = Qt.Edge(0)
pos = event.globalPos() - self.pos()
if pos.x() < self.BORDER_WIDTH:
edges |= Qt.LeftEdge
if pos.x() >= self.width()-self.BORDER_WIDTH:
edges |= Qt.RightEdge
if pos.y() < self.BORDER_WIDTH:
edges |= Qt.TopEdge
if pos.y() >= self.height()-self.BORDER_WIDTH:
edges |= Qt.BottomEdge
# change cursor
if et == QEvent.MouseMove and self.windowState() == Qt.WindowNoState:
if edges in (Qt.LeftEdge | Qt.TopEdge, Qt.RightEdge | Qt.BottomEdge):
self.setCursor(Qt.SizeFDiagCursor)
elif edges in (Qt.RightEdge | Qt.TopEdge, Qt.LeftEdge | Qt.BottomEdge):
self.setCursor(Qt.SizeBDiagCursor)
elif edges in (Qt.TopEdge, Qt.BottomEdge):
self.setCursor(Qt.SizeVerCursor)
elif edges in (Qt.LeftEdge, Qt.RightEdge):
self.setCursor(Qt.SizeHorCursor)
else:
self.setCursor(Qt.ArrowCursor)
elif et == QEvent.MouseButtonPress and edges:
self.windowHandle().startSystemResize(edges)
print(1)
app = QApplication(sys.argv)
win = MainWindow()
win.show()
app.exec_()
但它不能很好地工作。请观看视频或链接。有时它就是不能工作,有时它不能调整到正确的大小。如果我删除pythonocc的代码,它将没有问题。所以这可能是pythonocc的问题。如何修复这个bug?
我的系统信息:
❯ neofetch
_,met$$$$$gg. tim@tim
,g$$$$$$$$$$$$$$$P. -------
,g$$P" """Y$$.". OS: Debian GNU/Linux 11 (bullseye) x86_64
,$$P' `$$$. Host: 81BV Lenovo ideapad 720S-13IKB
',$$P ,ggs. `$$b: Kernel: 5.10.0-21-amd64
`d$$' ,$P"' . $$$ Uptime: 21 hours, 55 mins
$$P d$' , $$P Packages: 3331 (dpkg), 13 (flatpak), 2 (snap)
$$: $$. - ,d$$' Shell: bash 5.1.4
$$; Y$b._ _,d$P' Resolution: 1920x1080
Y$$. `.`"Y$$$$P"' DE: Plasma 5.20.5
`$$b "-.__ WM: KWin
`Y$$ Theme: NephriteLight [Plasma], Breeze [GTK2/3]
`Y$$. Icons: breeze-dark [Plasma], breeze-dark [GTK2/3]
`$$b. Terminal: konsole
`Y$$b. Terminal Font: Hack [SRC] 10
`"Y$b._ CPU: Intel i5-8250U (8) @ 3.400GHz
`""" GPU: Intel UHD Graphics 620
Memory: 5873MiB / 7706MiB
我不知道该怎么办。请帮帮我!
这是QT中的一个错误,正如您所发现的,当子部件是本机窗口时,它会发生。由于X11复杂的生态系统(多个窗口管理器和多个合成器),startSystemResize()
API在X11上是脆弱的。如何报告问题?这里有一个类似的开放问题。
因此,现在,您需要通过处理鼠标事件来实现自己的调整大小逻辑。检查QSizeGrip实现