Beispiel #1
0
 def mousePressEvent(self, e: QtGui.QMouseEvent):
     self.position = QPoint(e.globalX() - self.geometry().x(),
                            e.globalY() - self.geometry().y())
     if not self.m_isEditing:
         return
     if not self.m_infocus:
         return
     if not e.buttons() and QtCore.Qt.LeftButton:
         self.setCursorShape(e.pos())
         return
     if e.button() == QtCore.Qt.RightButton:
         self.popupShow(e.pos())
         e.accept()
Beispiel #2
0
 def mouseMoveEvent(self, event: QMouseEvent):
     if self.isPressed: self.move(event.globalX() - self.mousePos[0], event.globalY() - self.mousePos[1])
Beispiel #3
0
 def mouseMoveEvent(self, event: qtg.QMouseEvent) -> None:
     self.window().move(event.globalX() - 720, event.globalY() - 30)
     self.window().setWindowOpacity(0.7)
Beispiel #4
0
    def mouseMoveEvent(self, e: QtGui.QMouseEvent):
        QWidget.mouseMoveEvent(self, e)
        if not self.m_isEditing:
            return
        if not self.m_infocus:
            return
        if not e.buttons() and QtCore.Qt.LeftButton:
            p = QPoint(e.x() + self.geometry().x(),
                       e.y() + self.geometry().y())
            self.setCursorShape(p)
            return

        if (self.mode == Mode.MOVE or self.mode
                == Mode.NONE) and e.buttons() and QtCore.Qt.LeftButton:
            toMove = e.globalPos() - self.position
            if toMove.x() < 0: return
            if toMove.y() < 0: return
            if toMove.x() > self.parentWidget().width() - self.width(): return
            self.move(toMove)
            self.newGeometry.emit(self.geometry())
            self.parentWidget().repaint()
            return
        if (self.mode != Mode.MOVE) and e.buttons() and QtCore.Qt.LeftButton:
            if self.mode == Mode.RESIZETL:  # Left - Top
                newwidth = e.globalX() - self.position.x() - self.geometry().x(
                )
                newheight = e.globalY() - self.position.y() - self.geometry(
                ).y()
                toMove = e.globalPos() - self.position
                self.resize(self.geometry().width() - newwidth,
                            self.geometry().height() - newheight)
                self.move(toMove.x(), toMove.y())
            elif self.mode == Mode.RESIZETR:  # Right - Top
                newheight = e.globalY() - self.position.y() - self.geometry(
                ).y()
                toMove = e.globalPos() - self.position
                self.resize(e.x(), self.geometry().height() - newheight)
                self.move(self.x(), toMove.y())
            elif self.mode == Mode.RESIZEBL:  # Left - Bottom
                newwidth = e.globalX() - self.position.x() - self.geometry().x(
                )
                toMove = e.globalPos() - self.position
                self.resize(self.geometry().width() - newwidth, e.y())
                self.move(toMove.x(), self.y())
            elif self.mode == Mode.RESIZEB:  # Bottom
                self.resize(self.width(), e.y())
            elif self.mode == Mode.RESIZEL:  # Left
                newwidth = e.globalX() - self.position.x() - self.geometry().x(
                )
                toMove = e.globalPos() - self.position
                self.resize(self.geometry().width() - newwidth, self.height())
                self.move(toMove.x(), self.y())
            elif self.mode == Mode.RESIZET:  # Top
                newheight = e.globalY() - self.position.y() - self.geometry(
                ).y()
                toMove = e.globalPos() - self.position
                self.resize(self.width(), self.geometry().height() - newheight)
                self.move(self.x(), toMove.y())
            elif self.mode == Mode.RESIZER:  # Right
                self.resize(e.x(), self.height())
            elif self.mode == Mode.RESIZEBR:  # Right - Bottom
                self.resize(e.x(), e.y())
            self.parentWidget().repaint()
        self.newGeometry.emit(self.geometry())


# class MainWindow(QMainWindow):
#     def __init__(self):
#         super().__init__()

#         self.showMaximized()
#         lab1 = QLabel("Label1")
#         lab2 = QLabel("Label2")
#         con1 = TContainer(self, QPoint(10,10), lab1)
#         con2 = TContainer(self, QPoint(20,50), lab2)

# if __name__ == '__main__':
#     app = QApplication(sys.argv)
#     ex = MainWindow()
#     sys.exit(app.exec_())