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. drawing on coordinates built from visibleRegion() leave a trace on the screen

drawing on coordinates built from visibleRegion() leave a trace on the screen

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 262 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.
  • D Offline
    D Offline
    Daniel Santos
    wrote on last edited by
    #1

    Hello,

    I have a widget that contains a set of tiles, that together form a map.
    The widget is scrollable in X and Y directions. Now I want to do custom drawing on the widget that stays always independent of scroll position on the same spot.
    I am doing it based on the visibleRegion() method.

        QRegion visibleRegion = this->visibleRegion();
        auto regionIt = visibleRegion.begin();
        QRect visibleRect = *regionIt;
        int rightx = visibleRect.topRight().x() - 10;
        int topy = visibleRect.topRight().y() + 10;
        int leftx = rightx - widthOfNav;
        int bottomy = topy + heightOfNav;
    
        QRect navSquare = QRect(leftx, topy, widthOfNav, heightOfNav);
        painter->drawRect(navSquare);
    
    

    But when I scroll the view, the drawing leaves a trace of the previously drawn rectangles. I thought that the draw routine was called for each scroll position and doing that I am overwriting all the pixels in the window because :

    • I draw all the images visible (also using the visibleRegion() method
    • I draw the rect on top of the images

    Can anyone explain to me what is happening here ?
    Thanks,
    Regards

    Christian EhrlicherC 1 Reply Last reply
    0
    • D Daniel Santos

      Hello,

      I have a widget that contains a set of tiles, that together form a map.
      The widget is scrollable in X and Y directions. Now I want to do custom drawing on the widget that stays always independent of scroll position on the same spot.
      I am doing it based on the visibleRegion() method.

          QRegion visibleRegion = this->visibleRegion();
          auto regionIt = visibleRegion.begin();
          QRect visibleRect = *regionIt;
          int rightx = visibleRect.topRight().x() - 10;
          int topy = visibleRect.topRight().y() + 10;
          int leftx = rightx - widthOfNav;
          int bottomy = topy + heightOfNav;
      
          QRect navSquare = QRect(leftx, topy, widthOfNav, heightOfNav);
          painter->drawRect(navSquare);
      
      

      But when I scroll the view, the drawing leaves a trace of the previously drawn rectangles. I thought that the draw routine was called for each scroll position and doing that I am overwriting all the pixels in the window because :

      • I draw all the images visible (also using the visibleRegion() method
      • I draw the rect on top of the images

      Can anyone explain to me what is happening here ?
      Thanks,
      Regards

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      @Daniel-Santos said in drawing on coordinates built from visibleRegion() leave a trace on the screen:

      Can anyone explain to me what is happening here ?

      When you scroll only the new parts are painted when you don't invalidate others which you must when you want to draw something without the state of the current scroll position.

      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
      • D Offline
        D Offline
        Daniel Santos
        wrote on last edited by
        #3

        Got it. I connected two event handlers, each on the horizontal and vertical scrollers to repaint on scroll and it now works.

        Thanks

        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