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 Painter drawLine doubt

    Hi

    I have use QPainter to drawlines. I draw a line based on the mouse pointer's current position. My problem is when the mouse moves the new lines are drawn but the old one's remain. Can anyone just how to remove the old lines.

    I use the following command:
    painter->drawLine(0, 0, x1, y1);
    where x1, y1 is the current position of the mouse.
    Also, when I point the mouse back to an old position where there was a line already drawn, the line disappaers. I do not understand why the old lines disappear when it should be redrawn. Could someone explain me the concept?

    Thanks
    Arjun

  2. #2
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    40
    Thanked 8 Times in 4 Posts

    Default Re: Painter drawLine doubt

    Hi,

    On which widget are you performing the drawing?

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  3. #3
    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

  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

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

  5. #5
    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

  6. #6
    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.