Results 1 to 13 of 13

Thread: [qt4.1,win,g++] Using QPainter outside paintEvent()

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default [qt4.1,win,g++] Using QPainter outside paintEvent()

    hi,

    how can i draw on a widget outside method paintevent() ?
    in the following code the lines are drawn in paintevent(9 but not
    in mousemoveevent(). i tried several attributes such as
    Qt::WA_PaintOutsidePaintEvent but without success.


    void paintEvent(QPaintEvent *e)
    {
    QLabel:aintEvent(e);
    QPainter p(this);
    p.setPen(QColor(146, 146, 146));
    p.drawRect(0, 0, width() - 5, height() - 5);
    }


    virtual void mouseMoveEvent ( QMouseEvent * e )
    {
    QPainter p(this);
    QPen pen;
    pen.setColor(QColor(200,100,30));
    p.setPen( pen );
    p.drawLine(QPoint(0,0),e->pos());
    p.drawLine(0,0,100,60);
    }


    any ideas?

    jh

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [qt4.1,win,g++] Using QPainter outside paintEvent()

    Is that mouseMoveEvent() method being invoked at all?

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [qt4.1,win,g++] Using QPainter outside paintEvent()

    yes it is. i put some printf's in it to test it (which i just
    deleted in the posting)

    the method mousemoveevent is called.

    in each tutorial and example i found so far the painting is always done
    in paintevent. is there anything done by qt internally before paintevent
    is called which i have to do before painting (outside paintevent) ?

    jh

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [qt4.1,win,g++] Using QPainter outside paintEvent()

    The docs for Qt::WA_PaintOutsidePaintEvent say:
    Makes it possible to use QPainter to paint on the widget outside paintEvent(). This is not supported on Mac OS X. We recommend that you use this attribute only when porting Qt 3 code to Qt 4.
    How did you set this attribute?

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [qt4.1,win,g++] Using QPainter outside paintEvent()

    i set this attribute by calling setAttribute like this:

    virtual void mouseMoveEvent ( QMouseEvent * e )
    {

    setAttribute(Qt::WA_PaintOutsidePaintEvent, true);

    QPainter p(this);
    QPen pen;
    pen.setColor(QColor(200,100,30));
    p.setPen( pen );
    p.drawLine(QPoint(0,0),e->pos());
    p.drawLine(0,0,100,60);

    }


    regards,
    jh

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [qt4.1,win,g++] Using QPainter outside paintEvent()

    Did you try setting it in the constructor?

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [qt4.1,win,g++] Using QPainter outside paintEvent()

    yes. i also tried that.

    jh

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [qt4.1,win,g++] Using QPainter outside paintEvent()

    Is this a normal widget or does it use OpenGL?

  9. #9
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [qt4.1,win,g++] Using QPainter outside paintEvent()

    it's a normal widget derived from qlabel:



    class PaintTest : public QLabel
    {

    public:

    PaintTest( const QString & text, QWidget * parent = 0, Qt::WFlags f = 0 )
    : QLabel(text,parent,f)
    {
    setAttribute(Qt::WA_PaintOutsidePaintEvent,true);
    }

    protected:

    void ppp()
    {
    QPainter p(this);
    // setAttribute(Qt::WA_PaintOutsidePaintEvent,true);
    QPen pen(Qt:ashLine);
    pen.setColor(Qt::red);
    // p.s0etCompositionMode(QPainter::CompositionMode_Xo r);
    p.setPen( pen );
    p.drawLine(QPoint(0,0),QPoint(50,70));
    p.drawLine(0,0,100,100);
    printf("jdhfjkdshfjkhds\n");
    fflush(stdout);
    }

    void paintEvent(QPaintEvent *e)
    {
    QLabel:aintEvent(e);

    QPainter p(this);
    p.setPen(QColor(146, 146, 146));
    p.drawRect(0, 0, width() - 5, height() - 5);

    printf("paintEvent\n");
    fflush(stdout);

    }



    virtual void mouseMoveEvent ( QMouseEvent * e )
    {

    setAttribute(Qt::WA_PaintOutsidePaintEvent, true);

    QPainter p(this);
    QPen pen;
    pen.setColor(QColor(200,100,30));
    p.setPen( pen );
    p.drawLine(QPoint(0,0),e->pos());
    p.drawLine(0,0,100,60);

    // repaint(10,10,50,60);

    printf("mouseMoveEvent\n");
    fflush(stdout);

    }

    };


    jh

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [qt4.1,win,g++] Using QPainter outside paintEvent()

    It seems to work on my system (PLD Linux, Qt 4.1.0). See the attached image.

    PS. Please, use [ code ] tags to make your code readable.
    Attached Images Attached Images

  11. #11
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [qt4.1,win,g++] Using QPainter outside paintEvent()

    hm ...
    linux / win32 - OpSystem problem ?? strange.

    if anybody gets this working on win32, let me know!

    jh

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [qt4.1,win,g++] Using QPainter outside paintEvent()

    Quote Originally Posted by jh
    linux / win32 - OpSystem problem ?
    Yes, looks like a Qt bug.

    http://www.trolltech.com/developer/t...entry&id=83522

  13. #13
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [qt4.1,win,g++] Using QPainter outside paintEvent()

    ok, so it's not due to my incompetence

    i'll wait till 4.1.1

    thanx for the hint.

    jh

Similar Threads

  1. QPainter reuse within a paintEvent
    By Micawber in forum Qt Programming
    Replies: 2
    Last Post: 2nd May 2008, 16:51
  2. Replies: 3
    Last Post: 27th November 2006, 09:56
  3. QPainter ouside of paintEvent with a pixmap
    By bitChanger in forum Qt Programming
    Replies: 10
    Last Post: 22nd March 2006, 19:45
  4. Replies: 7
    Last Post: 20th March 2006, 20:03

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.