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. Qt equivalent of some Win32 code in OnMouseMove (mouseMoveEvent in Qt)
QtWS25 Last Chance

Qt equivalent of some Win32 code in OnMouseMove (mouseMoveEvent in Qt)

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 308 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by
    #1

    In the OnMouseMove() mf of a Win32 custom control which I am re-writing for Qt, there is some code that looks like this:

    //----- Get the original erase area -----//
    getMarkerRgn(&oldrgn);
    
    //----- Draw the markers -----//
    :
    :
    getMarkerRgn(&newrgn);
    
    erasergn.CreateRectRgn(0,0,0,0); //Dummy rgn
    erasergn.CombineRgn(&oldrgn, &newrgn, RGN_DIFF);
    dc.FillRgn(&erasergn, &brush); // Background colour brush
    

    The idea being to erase the previously drawn markers after the new ones are drawn

    What should I be doing in Qt?

    PS is there any Qt equivalent of the Windows OnEraseBackGround() ?
    PPS only three weeks Qt experience so far so please be gentle!

    Many thanks
    David

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Painting can only be done inside the paintEvent(): https://doc.qt.io/qt-5/paintsystem.html
      The mouse move events can be captured with QWidget::mouseMoveEvent()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • PerdrixP Offline
        PerdrixP Offline
        Perdrix
        wrote on last edited by
        #3

        So I can't paint inside the mouseMoveEvent() mf? Oh dear that's quite a problem.

        What I'm doing is dragging a shape and as it is dragged the previously drawn version must be erased and the new one drawn which is what that code does (there's more to it than that but you get the idea).

        So given that you seem to be saying "You can't get there from here" - how on earth do I handle this?

        Thanks
        David

        mrjjM 1 Reply Last reply
        0
        • PerdrixP Perdrix

          So I can't paint inside the mouseMoveEvent() mf? Oh dear that's quite a problem.

          What I'm doing is dragging a shape and as it is dragged the previously drawn version must be erased and the new one drawn which is what that code does (there's more to it than that but you get the idea).

          So given that you seem to be saying "You can't get there from here" - how on earth do I handle this?

          Thanks
          David

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Perdrix
          Hi
          You just keep the shape rect / x,y as members of the class.
          Then in MouseMove you alter its position and call update()
          Then paintEvent is called it it draw the shapes in the pos.

          To erase the old shape, the code
          // this you can do in mousePress Qt also has region https://doc.qt.io/qt-5/qregion.html
          erasergn.CreateRectRgn(0,0,0,0); //Dummy rgn
          erasergn.CombineRgn(&oldrgn, &newrgn, RGN_DIFF);

          // this goes to PaintEvent
          dc.FillRgn(&erasergn, &brush); // Background colour brush
          (change to use QPainter methods ofc)

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

            Hi,

            Just a side question since you are mentioning a shape and movement, depending on what you want to do, did you consider the use of the Graphics View Framework ?

            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
            2
            • PerdrixP Offline
              PerdrixP Offline
              Perdrix
              wrote on last edited by
              #6

              I did look at it but at the time didn't think it would be relevant.

              Right now I'm considering how much work it will be to work out how to only paint the invalidated region/rect versus the cost of just re-drawing the whole control.

              D.

              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