Results 1 to 4 of 4

Thread: Simple QtPainter problem

  1. #1
    Join Date
    Jan 2008
    Posts
    27
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Simple QtPainter problem

    Just trying to use a QPainter to draw a line across my widget. I thought it would be easy, just not working. Here is the entire widget code.

    Thanks.

    Qt Code:
    1. #ifndef TOPBAR_H_
    2. #define TOPBAR_H_
    3.  
    4. #include <QtGui/QWidget>
    5. #include <QPainter>
    6. #include "ui_TopBar.h"
    7.  
    8. class TopBar : public QWidget, private Ui::TopBarClass {
    9. Q_OBJECT
    10.  
    11. public:
    12. TopBar(QWidget *parent = 0) :
    13. QWidget(parent) {
    14. setupUi(this);
    15.  
    16. QPainter painter(this);
    17. painter.drawLine(0,21,240,21);
    18. }
    19. };
    20.  
    21. #endif /*TOPBAR_H_*/
    To copy to clipboard, switch view to plain text mode 

  2. #2
    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: Simple QtPainter problem

    You can draw on widgets only in their paint events.
    So, override paintEvent for your widget and do all the drawing in there.
    Don't forget to call the base class version if you want the widget to draw it's default contents.

  3. The following user says thank you to marcel for this useful post:

    rishid (5th February 2008)

  4. #3
    Join Date
    Jan 2008
    Posts
    27
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Simple QtPainter problem

    Yea I JUST found this too.

    They should list that in the QPainter documentation too.


    http://doc.trolltech.com/4.3/porting...rawing-widgets

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

    Default Re: Simple QtPainter problem

    Quote Originally Posted by rishid View Post
    They should list that in the QPainter documentation too.
    It's there, right in the beginning of the detailed description.
    J-P Nurmi

Similar Threads

  1. Simple Problem with QFont (point size)
    By mtrpoland in forum Newbie
    Replies: 4
    Last Post: 31st December 2007, 17:49
  2. Problem with simple Model-View in Qt4.3
    By ccf_h in forum Qt Programming
    Replies: 3
    Last Post: 17th June 2007, 19:57
  3. Replies: 2
    Last Post: 19th May 2007, 19:25
  4. Very simple problem with QServerSocket and Qsocket
    By eter in forum Qt Programming
    Replies: 2
    Last Post: 4th November 2006, 09:07
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

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.