Results 1 to 6 of 6

Thread: problem in QPainter::begin

  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default problem in QPainter::begin

    hi friends ,

    usually where this error occurs i cant find it ... when i run my code its giving
    Qt Code:
    1. QPainter::begin: A paint device can only be painted by one painter at a time.
    2. QPainter::begin: A paint device can only be painted by one painter at a time.
    3. QPainter::begin: A paint device can only be painted by one painter at a time.
    4. QPainter::begin: A paint device can only be painted by one painter at a time.
    5. QPainter::begin: A paint device can only be painted by one painter at a time.
    6. QPainter::begin: A paint device can only be painted by one painter at a time.
    7. QPainter::begin: A paint device can only be painted by one painter at a time.
    8. QPainter::begin: A paint device can only be painted by one painter at a time.
    9. Segmentation fault
    To copy to clipboard, switch view to plain text mode 

    and the core dump occurred ...

    can any one please explain where this problem arises ....
    "Behind every great fortune lies a crime" - Balzac

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem in QPainter::begin

    as the error says.. there are two active painters on same widget... search for... so there may be these cases

    1. QPainter p(this);
    2. p.begin();
    3 new QPainter(this);
    4. p->begin();

    now search for all those lines and put a qDebug on top of them... next time u will find which line was the second painter

    EDIT:
    alternatively.. go in qpainter.cpp and put a breakpoint at the line which says the error.. then u can see the call stack. Of course Qt must be in debug mode.
    EDIT2:
    after writing the above edit... i thought.. is it possible to put a break point in qpainter.cpp? i have not tried it..
    Last edited by nish; 17th July 2009 at 06:09.

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

    wagmare (17th July 2009)

  4. #3
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in QPainter::begin

    the problem arise here ..

    this graphicsItem CentralItem has an ability to add proxywidgets ... and its code
    Qt Code:
    1. CentralItem::CentralItem(const QRectF &rect, const QBrush &brush, QWidget *embeddedWidget)
    2. brush(brush)
    3. {
    4. if(embeddedWidget){
    5. proxyWidget = new QGraphicsProxyWidget(this);
    6. proxyWidget->setFocusPolicy(Qt::StrongFocus);
    7. proxyWidget->setWidget(embeddedWidget);
    8. proxyWidget->setPos(5, 5);
    9.  
    10. }
    11.  
    12. }
    13.  
    14. void CentralItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
    15. {
    16. painter->setPen(Qt::NoPen);
    17. painter->setBrush(QColor(0, 0, 0, 65));
    18. painter->drawRoundRect(rect().translated(2, 2));
    19.  
    20. painter->setPen(QPen(Qt::black, 1));
    21. painter->setBrush(brush);
    22. painter->drawRect(rect());
    23.  
    24. }
    To copy to clipboard, switch view to plain text mode 

    and i use it in one graphicsView which is a main window
    MainView where i embed a stacked widget ... and it works fine ...

    then the problem arise ...
    in the stacked widget there are QGraphicsView in individual pages ...

    so in one sub GraphicsView i try to use same CentralItem to embed a lineEdit and i receive this error ...



    did i confuse a lot ... ? see how i can find that in QPainter problem ...

    please help

    also take a look at this link ..
    https://bugs.launchpad.net/qbzr/+bug/234965
    "Behind every great fortune lies a crime" - Balzac

  5. #4
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in QPainter::begin

    i learned that

    "There is no way to add a widget inside a QGraphicsView that is embedded into another one"

    but is there any other way i can resolve this problem ...
    "Behind every great fortune lies a crime" - Balzac

  6. #5
    Join Date
    Jul 2009
    Location
    China,Shanghai
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in QPainter::begin

    Did you call the paintEvent, you need that to paint somthing on the widget. If you just write code like paintXXX and not call in the paintEvent, it`ll not work at all.
    Qt Code:
    1. void MyWidget::paintEvent(QPaintEvent *)
    2. {
    3.  
    4. QPainter painter(this);
    5. paintXXXX(QPainter *);
    To copy to clipboard, switch view to plain text mode 

  7. #6
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in QPainter::begin

    =xtfllbl;109807]Did you call the paintEvent, you need that to paint somthing on the widget. If you just write code like paintXXX and not call in the paintEvent, it`ll not work at all.
    actually its a bug in Qt ... we cant add a new widget to a widget that is embedded to graphicsView()

    see this code
    Qt Code:
    1. ProxyBug::ProxyBug(QWidget *parent) : QDialog(parent)
    2. {
    3. QVBoxLayout *l = new QVBoxLayout( this );
    4.  
    5. group->setScene(scene);
    6.  
    7. QGraphicsView * group2 = new QGraphicsView;
    8. group2->setScene(scene2);
    9.  
    10. group->scene()->addWidget(group2);
    11. QLineEdit * lineEdit = new QLineEdit;
    12. group2->scene()->addWidget(lineEdit); // this one crashing *
    13.  
    14. l->addWidget(group);
    15. setLayout( l );
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 

    the group2 is try to embed another widget where group2 itself is embedded by group ...
    Last edited by wagmare; 17th July 2009 at 10:40.
    "Behind every great fortune lies a crime" - Balzac

Similar Threads

  1. Replies: 1
    Last Post: 23rd April 2009, 09:05
  2. Replies: 19
    Last Post: 3rd April 2009, 23:17
  3. deployment problem: msvc++ 2008 Express, Qt 4.4.3
    By vonCZ in forum Qt Programming
    Replies: 7
    Last Post: 10th November 2008, 14:38
  4. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  5. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36

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.