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. How to change cursor to Qt.ForbiddenCursor while drag hover over a qlistwidget?
QtWS25 Last Chance

How to change cursor to Qt.ForbiddenCursor while drag hover over a qlistwidget?

Scheduled Pinned Locked Moved Solved Qt for Python
10 Posts 3 Posters 1.2k 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.
  • L Offline
    L Offline
    Leon Zhang
    wrote on last edited by Leon Zhang
    #1

    How to change the cursor icon to ForbiddenCursor while user drag item and hover mouse over a qlistwidget?
    I have tried:

    def dragEnterEvent(self, event):
            if event.mimeData().hasFormat('text/plain'):
                self.setCursor(qt.Qt.ForbiddenCursor)
                event.ignore()
            else:
                event.accept()
                qt.QListWidget.dragEnterEvent(self, event)
    

    but above code won't work while holding mouse left button down, setCursor works only after I release mouse left button.

    Thanks in advance.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You have to implement the drag enter and move events method and there not accept the proposed action.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Leon Zhang
        wrote on last edited by
        #3

        @SGaist Thanks, could you give a code example here?
        I have tried following:

        def mouseMoveEvent(self, event):
                if event.mimeData().hasFormat('text/plain'):
                     event.ignore()
        

        But the event in mouseMoveEvent does not have mimeData member method.

        JonBJ 1 Reply Last reply
        0
        • L Leon Zhang

          @SGaist Thanks, could you give a code example here?
          I have tried following:

          def mouseMoveEvent(self, event):
                  if event.mimeData().hasFormat('text/plain'):
                       event.ignore()
          

          But the event in mouseMoveEvent does not have mimeData member method.

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @Leon-Zhang
          QDragMoveEvent, not QMouseMoveEvent.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Not the mouse event handlers, the drag related event handlers.

            QWidget::dragEnterEvent
            QWidget::dragMoveEvent

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            L 1 Reply Last reply
            0
            • SGaistS SGaist

              Not the mouse event handlers, the drag related event handlers.

              QWidget::dragEnterEvent
              QWidget::dragMoveEvent

              L Offline
              L Offline
              Leon Zhang
              wrote on last edited by Leon Zhang
              #6

              @SGaist @JonB
              Thanks.
              I have another issue: I have an override of mouseMoveEvent function, and seems
              dragMoveEvent won't be called if mouseMoveEvent override presents.

              Any idea how to fix this? Thanks.

              JonBJ 1 Reply Last reply
              0
              • L Leon Zhang

                @SGaist @JonB
                Thanks.
                I have another issue: I have an override of mouseMoveEvent function, and seems
                dragMoveEvent won't be called if mouseMoveEvent override presents.

                Any idea how to fix this? Thanks.

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by JonB
                #7

                @Leon-Zhang
                That does not sound right, you having an override should not be relevant. Unless, at a guess, your override fails to call the base implementation, and that prevents the drag move event ever getting raised...?

                L 1 Reply Last reply
                0
                • JonBJ JonB

                  @Leon-Zhang
                  That does not sound right, you having an override should not be relevant. Unless, at a guess, your override fails to call the base implementation, and that prevents the drag move event ever getting raised...?

                  L Offline
                  L Offline
                  Leon Zhang
                  wrote on last edited by
                  #8

                  @JonB I have tried to remove dragEnterEvent override, and dragMoveEvent and mouseMoveEvent both been triggered now. Wired.

                  JonBJ 1 Reply Last reply
                  0
                  • L Leon Zhang

                    @JonB I have tried to remove dragEnterEvent override, and dragMoveEvent and mouseMoveEvent both been triggered now. Wired.

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by JonB
                    #9

                    @Leon-Zhang
                    I don't know what you're up to, but so far as I recall and as @SGaist said you will need to override both dragEnterEvent and dragMoveEvent to alter the cursor during a drag successfully.

                    L 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @Leon-Zhang
                      I don't know what you're up to, but so far as I recall and as @SGaist said you will need to override both dragEnterEvent and dragMoveEvent to alter the cursor during a drag successfully.

                      L Offline
                      L Offline
                      Leon Zhang
                      wrote on last edited by
                      #10

                      @JonB It seems async lock process affected the implementation of dragMoveEvent override, remove this lock solved the problem.

                      1 Reply Last reply
                      0

                      • Login

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