Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Dragable pyqt frameless app

Dragable pyqt frameless app

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 5 Posters 3.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    arkero24
    wrote on last edited by
    #1

    Morning.

    I have built an app with Qdesigner, with pyuic I created python code and made the app frameless. I added a qframe as a title bar which contains two qlabels, for icon and app info, and I added two qtoolbuttons for minimizing and close app. I need this bar title let me to move the app.

    How's that Possible?

    thank you very much

    jsulmJ 1 Reply Last reply
    0
    • A arkero24

      Morning.

      I have built an app with Qdesigner, with pyuic I created python code and made the app frameless. I added a qframe as a title bar which contains two qlabels, for icon and app info, and I added two qtoolbuttons for minimizing and close app. I need this bar title let me to move the app.

      How's that Possible?

      thank you very much

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @arkero24 Take a look at https://doc.qt.io/qt-5/qwidget.html#mouseMoveEvent
      You will need to store last mouse cursor position, then next time mouseMoveEvent is called you calculate mouse cursor position difference (current - last) and apply this difference to move your window.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • N Offline
        N Offline
        NonNT
        wrote on last edited by
        #3

        @arkero24
        Check this out: https://www.learnpyqt.com/apps/build-desktop-notes-application/
        Maybe that's what you're looking for.

        1 Reply Last reply
        0
        • W Offline
          W Offline
          wrosecrans
          wrote on last edited by
          #4

          Here's a draggable frameless widget that might be a useful starting point for you. It uses mouseMoveEvent() to move itself when dragged.

          class Marker(W.QWidget):
            def __init__(self, parent = None):
                W.QWidget.__init__(self, parent)
                self.setWindowFlags(QtCore.Qt.Widget | QtCore.Qt.FramelessWindowHint);
                self.setAttribute(QtCore.Qt.WA_NoSystemBackground, True);
                self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True);
                self.clicked = False
            def paintEvent(self, ev):
                p = Gui.QPainter(self)
                p.fillRect(self.rect(), Gui.QColor(128, 128, 128, 128))
                
            def mousePressEvent(self, ev):
                self.old_pos = ev.screenPos()
          
            def mouseMoveEvent(self, ev):
                if self.clicked:
                  dx = self.old_pos.x() - ev.screenPos().x()
                  dy = self.old_pos.y() - ev.screenPos().y()
                  self.move(self.pos().x() - dx, self.pos().y() - dy)
                self.old_pos = ev.screenPos()
                self.clicked = True
                return W.QWidget.mouseMoveEvent(self, ev)
          
          
          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved