Results 1 to 6 of 6

Thread: QCanvas clipping problems

  1. #1
    Join Date
    Mar 2006
    Location
    Troy, Michigan, USA
    Posts
    17
    Thanks
    2
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default QCanvas clipping problems

    I need to be able to clip my canvas to a given rectangle. I tried sub-classing from the QCanvas widget and added my own virtual functions for drawForeground and drawBackground. I then tried to set clipping on and set a clip rect for the painter in both functions, which didn't work.
    So then I tried to just add a return statement at the top of both functions, but the foreground always gets painted.
    Can someone tell me what I am doing wrong, and more importantly, why is it drawing anything at all when I am just returning from the draw functions?

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

    Default Re: QCanvas clipping problems

    I think it will be easiest if you reimplement drawContents() from QCanvasView. There you can clip the painter to a desired rectangle and call the base class implementation.

  3. #3
    Join Date
    Mar 2006
    Location
    Troy, Michigan, USA
    Posts
    17
    Thanks
    2
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QCanvas clipping problems

    Yeah that's what I thought too. Here is what I tried, which still draw the entire canvas:

    void myCanvasView::drawContents(QPainter *p, int cx, int cy, int cw, int ch)
    {
    QRect myRect(20, 20, 50, 50);

    p->setClipRect(myRect);
    p->setClipping(true);

    QCanvasView::drawContents(p, myRect.x(), myRect.y(), myRect.width(), myRect.height());
    }

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

    Default Re: QCanvas clipping problems

    You should certainly call the base class implementation with the values you received, so cx, cy, cw and ch in this case. And check if your implementation is called at all.

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCanvas clipping problems

    No, you should call the base class version with the values you clip the painter: 20, 20, 50 ,50.

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

    Default Re: QCanvas clipping problems

    Quote Originally Posted by marcel View Post
    No, you should call the base class version with the values you clip the painter: 20, 20, 50 ,50.
    Hmm... Why so?

Similar Threads

  1. Replies: 7
    Last Post: 20th March 2006, 20:03

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.