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
    Posts
    667
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    10
    Thanked 80 Times in 74 Posts

    Default Re: QScrollView and repaint

    Can you please do me a favor ?

    Can you try it with the following code ? It should draw red horizontal lines, right ?

    [CODE]

    void drawContents(QPainter *p, int cx, int cy, int cw, int ch)
    {
    //p->setClipRect(cx,cy,cw,ch);
    // p->setClipping(true);
    p->fillRect(0,0,600,300, Qt::white);
    p->setPen(Qt::red);
    for(int i = 0; i < 300; i+=25){
    p->drawLine(0,i, 600, i);
    }
    }

    [CODE]

    Once you have the drawing, resize your browser( or any other window) and move it around this drawing.

    Are the lines getting drawn as the new area is shown and the window is moved ?

    Thanks a lot.

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

    Default Re: QScrollView and repaint

    No, they don't.

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

    Default Re: QScrollView and repaint

    Shouldn't the lines be drawn as I move the window ? I mean, shouldn't the drawContents be called and the drawing should be updated?

    Now, since we know that drawContents is not called, is there a way be which I can detect this and call repaint()

    Thanks a lot for your time.
    Thanks a lot

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

    Default Re: QScrollView and repaint

    Any ideas on this one ?

    Thanks.

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

    Default Re: QScrollView and repaint

    A simple way around this is to add a child widget to the scrollview and do all the drawing in the paint event of the widget.

    Qt Code:
    1. class MyWidget : public QWidget{
    2. public:
    3. MyWidget(QWidget *parent = 0) : QWidget(parent){}
    4. protected:
    5. void paintEvent(QPaintEvent *pe){
    6. //...
    7. }
    8. };
    9. //...
    10. wid = new MyWidget(viewport());
    11. wid.resize(600, 400);
    12. //...
    To copy to clipboard, switch view to plain text mode 

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.