Results 1 to 2 of 2

Thread: drawLine not working

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2011
    Posts
    55
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default drawLine not working

    I'd like to draw a simple line into a frame, but nothing is showing. What I'm doing wrong? Thanks

    void myClass:buildInterface()
    {
    QFrame *myFrame;
    ........
    QPainter *p;
    p=new QPainter();
    p->begin(myFrame);
    p->drawLine( QPoint(0,0), QPoint(500,500) );
    p->end();
    }

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: drawLine not working

    You need to subclass the QFrame and reimplement paintEvent, its the only valid way to paint on widgets:
    Painting using a QPainter can only take place in a paintEvent() or a function called by a paintEvent().

Similar Threads

  1. drawLine with QGradient is slow
    By D.Dupuis in forum Qt Programming
    Replies: 0
    Last Post: 7th December 2011, 12:35
  2. How to drawline in a QWidget or any onther?
    By yangyunzhao in forum Qt Programming
    Replies: 2
    Last Post: 28th August 2009, 07:19
  3. DrawLine over QPixmap within Qlabel
    By Qt Coder in forum Qt Programming
    Replies: 8
    Last Post: 26th March 2009, 12:21
  4. QTransform + drawLine ?
    By verburg in forum Qt Programming
    Replies: 0
    Last Post: 23rd January 2009, 00:32
  5. Painter drawLine doubt
    By arjunasd in forum Qt Programming
    Replies: 5
    Last Post: 24th August 2007, 19:59

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.