Results 1 to 6 of 6

Thread: Painter drawLine doubt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2007
    Posts
    39
    Thanks
    10

    Default Re: Painter drawLine doubt

    Hi

    I have a QGraphicsView and I am trying to draw the lines on the widget.

    Also, I found the following piece of code while browsing. Its in Qt3.
    They have a QScrollView and they paint the lines as follows:

    painter->drawLine(x1,y1, x2, y2);

    change the values of x's and y's

    painter->drawLine(x1,y1, x2, y2);
    They comment the 1st draw clears the previous line and second draws the new line. How does this work? Sorry if its a naive question?

    Arjun

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: Painter drawLine doubt

    QGraphicsView caches its content. It is not suggested to draw by hand on GV. Perhaps you could use QGraphicsLineItems intead?
    J-P Nurmi

  3. #3
    Join Date
    Jul 2007
    Posts
    39
    Thanks
    10

    Default Re: Painter drawLine doubt

    Thanks. It works fine with QGraphicsLineItem.

    Just out of curiosity, regarding the sample code I got from the internet. Its in Qt3.They have a QScrollView and they paint the lines as follows:
    painter->drawLine(x1,y1, x2, y2);
    change the values of x's and y's
    painter->drawLine(x1,y1, x2, y2);

    They comment the 1st draw clears the previous line and second draws the new line. How does this work?

    Thanks
    Arjun

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: Painter drawLine doubt

    Quote Originally Posted by arjunasd View Post
    How does this work?
    Hard to say without seeing the exact code. Maybe they switch colors in between?

    Anyway, the painting system has pretty much changed in Qt 4. One can no more paint outside QWidget::paintEvent(). For more details, see Porting to Qt 4 - Painting and Redrawing Widgets and The Arthur Paint System.
    J-P Nurmi

Similar Threads

  1. How to manage QPainter?
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 13:20

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.