Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. prevent cursor from redrawing

prevent cursor from redrawing

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.4k Views 3 Watching
  • 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
    allenby
    wrote on last edited by
    #1

    I am trying to create a small box that follows the mouse cursor over an image to select a specific part of it.

    The box is a subclassed QLabel with the flags set to:
    Qt::CustomizeWindowHint|Qt::FramelessWindowHint|Qt::Tool
    The background set to:
    Qt::WA_TranslucentBackground.

    The mouseMoveEvent is used to move the box when the cursor is over the image widget. The enterEvent and leaveEvent detect this.
    The mouseMoveEvent is also used to update the cursor coordinates displayed in the status bar. The leaveEvent is used to clear the status bar text.

    This works really great, as long as the box and the cursor do not overlap. The box and the statusbar text behave as expected..

    However, because the box needs to be centred over the mouse hotspot, there is an overlap between the cursor and the box. This causes the box to flicker continually, and when the mouse is outside the image, the status bar text flickers as well, which indicates that even though the mouse cursor is not over the image, the widget must be receiving ongoing leaveEvents.

    I have tried setting the cursor to Qt::BlankCursor, but this has no effect.

    Any suggestions on how to prevent the flicker would be appreciated. Although I would prefer to still see the mouse pointer, I would happily have this hidden if that were the only solution.
    Thanks
    allenb

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

      Hi and welcome to devnet,

      Which version of Qt are you using ?
      On which OS ?
      Can you provide a minimal compilable example that shows this behavior ?

      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
      • A Offline
        A Offline
        allenby
        wrote on last edited by
        #3

        Hi SGaist, Thank you :)
        I am using Qt 5.15.2

        I have attached a small example that contains three classes:
        A mainwindow, a testwidget and a box. The testwidget and box are both subclasses of QLabel.
        The mainwindow contains the testwidget, the testwidget captures mouse events which move the box to follow the mouse.
        Even when the mouse is not moving, the box flickers continually.

        Oh, I tried to upload the file, but received the message that "I do not have enough privileges for this action"
        It can be downloaded here:
        https://www.dropbox.com/scl/fi/o493be8f997ti29p037rc/QtCursorExample.zip?rlkey=ck18a9zqzb2r9q3vb7ig2zqoj&st=gjlg1mpx&dl=0
        Thanks,
        fallen

        1 Reply Last reply
        0
        • A Offline
          A Offline
          allenby
          wrote on last edited by
          #4

          I am really tearing my hair out with this one. I put it aside for a while, hoping that a break from it would give me a fresh perspective, but I still can't figure out what is causing the problem.

          As mentioned above, I have a small test program containing three classes:
          A mainwindow, a testwidget and a box. The testwidget and box are both subclasses of QLabel.
          The mainwindow contains the testwidget, the testwidget captures mouse events which move the box to follow the mouse.

          However, even when the mouse is not moved, the box is continually redrawn and flickers constantly.

          I tried posting the sample code here, however, it was flagged as spam by Akismet. I will try to follow up this message with the code.

          I am sure that I am missing something very obvious, but I just can't see what it is, so any advice would be greatly appreciated.
          Thanks,
          Allen

          1 Reply Last reply
          0
          • A Offline
            A Offline
            allenby
            wrote on last edited by
            #5

            OK,

            THIS IS INCREDIBLY FRUSTRATING!

            I tried to post just the contents of the header file between code tags. It contains three small class declarations, about 30 lines of code.

            I hit the submit button and immediately received a message that I had to wait 600 seconds.
            After patiently waiting for 10 minutes and hitting submit again, aargh ...... "Code content was flagged as spam by Akismet"!

            So I have no idea how this forum works or if it even does, it seems to me to be pointless having a programming forum that can't even accept the most basic bit of code.

            `

            1 Reply Last reply
            0
            • Kent-DorfmanK Offline
              Kent-DorfmanK Offline
              Kent-Dorfman
              wrote on last edited by
              #6

              What about rather than trying to have a widget follow the cursor, if you make a custom cursor? Might be possible, and IMHO, woudl be a cleaner solution.

              If you meet the AI on the road, kill it.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                allenby
                wrote on last edited by allenby
                #7

                Kent, thanks for the response. This was my first thought as well, using a pixmap:

                QCursor cursor = QCursor(pixmap);
                setCursor(cursor);
                

                However, for this application, the cursor needs to be scalable so that it adjusts its size as the image being selected is zoomed in or out.
                Scaling the pixmap did not give the results I was looking for. However, in the interim, I have managed to find a solution thanks to someone on Stack Overflow.

                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