Results 1 to 3 of 3

Thread: How to drawline in a QWidget or any onther?

  1. #1
    Join Date
    Jun 2009
    Posts
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default How to drawline in a QWidget or any onther?

    I want to drawline in a QWidget or any other suitable controls.

    Somebody tolds me can overload paintEvent().

    1.If I use QT designer to create UI, I cannot drawline with this codes:
    Qt Code:
    1. void iLCDEmulator::paintEvent(QPaintEvent *)
    2. {
    3. QPainter paint(ui.displayWidget); //ui.displayWidget is a QWidget.
    4. //If use "QPainter paint(this) " ,it will drawline in my main windows.
    5. paint.setPen(Qt::red);
    6. paint.drawLine(0,0,50,50);
    7. }
    To copy to clipboard, switch view to plain text mode 

    2.If overload paintEvent(), this function will be called at the program statrs or "the widget was obscured and has now been uncovered".
    I just want to drawline when I need. And I want to control the line's positon uncontrolled.

  2. #2
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to drawline in a QWidget or any onther?

    You must overload paintEvent() in class which you want to drawline.
    east or west home is best

  3. #3
    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: How to drawline in a QWidget or any onther?

    Quote Originally Posted by yangyunzhao View Post
    I just want to drawline when I need. And I want to control the line's positon uncontrolled.
    Could you elaborate on that?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Promoting the parent QWidget of a QWidget form
    By extrakun in forum Qt Tools
    Replies: 6
    Last Post: 16th April 2010, 14:19
  2. Replies: 0
    Last Post: 11th November 2008, 15:36
  3. Dynamic updates of a QWidget in a QScrollArea
    By plamkata in forum Qt Programming
    Replies: 2
    Last Post: 20th July 2008, 23:45
  4. Error in put one QWidget in another QWidget
    By xjtu in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2008, 16:05
  5. Replies: 3
    Last Post: 8th March 2007, 14:54

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.