Results 1 to 17 of 17

Thread: QScrollView and repaint

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QScrollView and repaint

    Maybe you reimplemented drawContents incorrectly? QScrollView should trigger a paint event (and eventually drawContents) after part of the widget gets obscured. Could you give more details, what exactly did you do?

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QScrollView and repaint

    Here is my code :

    Qt Code:
    1. void Paper::drawContents(QPainter *p, int cx, int cy, int cw, int ch)
    2. {
    3. QPixmap pm(cw, ch);
    4. QPainter *pmp = new QPainter( &pm );
    5. pmp->setBrush( white );
    6. pmp->setPen( NoPen );
    7. pmp->drawRect( 0, 0, cw, ch);
    8. pmp->setPen( black );
    9. pmp->translate( -cx, -cy );
    10.  
    11. //My drawing code. Everything is done useing pmp
    12.  
    13. pmp->end();
    14. p->drawPixmap( cx, cy, pm );
    15. p->end();
    16. delete pmp;
    17. }
    To copy to clipboard, switch view to plain text mode 

    Thanks a lot

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QScrollView and repaint

    I think the translation might be messing the things up (I think the code is incorrect). Try getting rid of the pixmap at all and draw the whole viewport directly. If it helps, you can then optimise some things to get better results.

  4. #4
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QScrollView and repaint

    Here is the new code :

    Qt Code:
    1. void Paper::drawContents(QPainter *pmp, int cx, int cy, int cw, int ch)
    2. {
    3. //QPixmap pm(cw, ch);
    4. //QPainter *pmp = new QPainter( &pm );
    5. pmp->setBrush( white );
    6. pmp->setPen( NoPen );
    7. pmp->drawRect( 0, 0, cw, ch);
    8. //pmp->setPen( black );
    9. //pmp->translate( -cx, -cy );
    10.  
    11. //My drawing code
    12. }
    To copy to clipboard, switch view to plain text mode 

    It did not solve the first problem. Also, now flickering is introduced.
    Does this has to do something with contentsHeight and contentsWidth ?

    Thanks a lot for your time

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QScrollView and repaint

    How about:

    Qt Code:
    1. void Paper::drawContents(QPainter *pmp, int cx, int cy, int cw, int ch)
    2. {
    3. pmp->setClipRect(cx,cy,cw,ch);
    4. pmp->setClipping(true);
    5. pmp->fill(Qt::white);
    6. //Your drawing code
    7. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QScrollView and repaint

    It does not work.

    Also, if I do not translate, and when scrollbars appear, all the drawing is messed up.

    Please Help
    Thanks a lot

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QScrollView and repaint

    It should work. Did you reimplement some other methods too? Maybe the viewport isn't set up correctly?

Similar Threads

  1. repaint help pls
    By munna in forum Qt Programming
    Replies: 3
    Last Post: 21st June 2006, 10:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.