Results 1 to 8 of 8

Thread: QPainter problem - migration from qt3 [SOLVED]

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2006
    Posts
    6
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QPainter problem - migration from qt3 [SOLVED]

    Hi,
    I had the following code in qt3 and it worked perfectly (I removed resize and refresh procedures)
    whiteboard.h
    Qt Code:
    1. class Whiteboard : public QFrame
    2. {
    3. Q_OBJECT
    4. public:
    5. QPoint qt_currMosePos;
    6. QPoint qt_prevMousePos;
    7. QPen *pen;
    8. QPainter * paint;
    9.  
    10. Whiteboard( QWidget *parent=0, const char* name = 0);
    11. ~Whiteboard()
    12.  
    13. protected:
    14. void mouseMoveEvent(QMouseEvent *);
    15. void mousePressEvent(QMouseEvent *);
    16. };
    To copy to clipboard, switch view to plain text mode 

    whiteboard.cpp
    Qt Code:
    1. #include "whiteboard.h"
    2.  
    3. Whiteboard::Whiteboard( QWidget *parent, const char* name) : QFrame(parent,name)
    4. {
    5. paint = new QPainter(this);
    6. pen = new QPen(Qt::red,2);
    7. paint->setPen(*pen);
    8. this->setBackgroundMode(Qt::NoBackground);
    9. }
    10. Whiteboard::~Whiteboard()
    11. {
    12. delete paint;
    13. }
    14.  
    15. void Whiteboard::mouseMoveEvent(QMouseEvent *e)
    16. {
    17. qt_currMousePos = e->pos();
    18. paint->drawLine(qt_prevMousePos,qt_currMosePos);
    19. qt_prevMousePos = qt_currMousePos;
    20. }
    21.  
    22. void Whiteboard::mousePressEvent(QMouseEvent *e)
    23. {
    24. if(e->button() == Qt::LeftButton) {
    25. qt_prevMousePos = e->pos();
    26. paint->drawLine(qt_prevMousePos,qt_prevMousePos);
    27. }
    28. }
    To copy to clipboard, switch view to plain text mode 

    Basically it allows you to plot on the widget with your mouse.
    I compiled it under Solaris and Linux.

    Now I migrated to qt4. I ran qt3to4 and recompiled it. No problems.
    But when I launch the program I cannot paint and I have the following message in the console:
    QPainter::begin: Widget painting can only begin as a result of a paintEvent

    What has happend? Are there some new limitations in qt4?
    I know that migration from qt3 has been discussed since long time ago but I cannot find any mention of this problem.
    Thanks for help

    Tomek
    Last edited by tpomorsk; 28th August 2006 at 14:37.

Similar Threads

  1. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  2. Replies: 7
    Last Post: 20th March 2006, 20:03
  3. Replies: 16
    Last Post: 7th March 2006, 15:57
  4. QPainter rotate function
    By ir210 in forum Newbie
    Replies: 3
    Last Post: 17th January 2006, 04:31
  5. passing a QPainter object to widgets
    By vratojr in forum Qt Programming
    Replies: 9
    Last Post: 11th January 2006, 15:27

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.