Exemple #1
0
        public new bool EventFilter(QObject obj, QEvent evnt)
        {
            var type = evnt.type();

            if (type == QEvent.TypeOf.MouseButtonPress)
            {
                var mouseEvent = (QMouseEvent)evnt;
                if (mouseEvent.Button() == Qt.MouseButton.LeftButton)
                {
                    m_Moving = true;
                    m_OrigX  = mouseEvent.X();
                    m_OrigY  = mouseEvent.Y();
                    m_ParentWidget.Cursor = new QCursor(Qt.CursorShape.SizeAllCursor);
                }
            }
            else if (type == QEvent.TypeOf.MouseMove)
            {
                var mouseEvent = (QMouseEvent)evnt;
                if (m_Moving)
                {
                    var pos = mouseEvent.GlobalPos();
                    m_ParentWidget.Move(pos.X() - m_OrigX, pos.Y() - m_OrigY);
                }
            }
            else if (type == QEvent.TypeOf.MouseButtonRelease)
            {
                var mouseEvent = (QMouseEvent)evnt;
                if (m_Moving && mouseEvent.Button() == Qt.MouseButton.LeftButton)
                {
                    m_Moving = false;
                    m_ParentWidget.Cursor = new QCursor(Qt.CursorShape.ArrowCursor);
                }
            }

            return(obj.EventFilter(obj, evnt));
        }
Exemple #2
0
        public static void CenterWidgetOnScreen(QWidget widget)
        {
            QRect rect = QApplication.Desktop().AvailableGeometry(widget);

            widget.Move((rect.Width() / 2) - (widget.Rect.Width() / 2), (rect.Height() / 2) - (widget.Rect.Height() / 2));
        }