Tim
Tim

Reputation: 21

There is some problent with windowHandle().startSystemResize(edges) and pythonocc

This is my code

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_()

But it can't work well.Please watch the video or link. Sometimes it just can't work,sometimes it can't adjust to the correct size. If I delete the code what about pythonocc,It will has no problent.So maybe it's pythonocc's problent.How to fix this bug?

My system information:

❯ 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

I don't know what should I do.Please help me!

Upvotes: 1

Views: 157

Answers (1)

relent95
relent95

Reputation: 4732

It's a bug in QT. As you have found, it occurs when the child widget is a native window. The startSystemResize() API is fragile on X11 due to the complex X11 eco-system(multiple window managers and multiple compositors). What about reporting the issue? There's a similar open issue here.

So, for now, you need to implement your own resizing logic by handling mouse events. Check the QSizeGrip implementation.

Upvotes: 0

Related Questions