View Full Version : problem in QPainter::begin
wagmare
17th July 2009, 05:59
hi friends ,
usually where this error occurs i cant find it ... when i run my code its giving
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::begin: A paint device can only be painted by one painter at a time.
Segmentation fault
and the core dump occurred ...
can any one please explain where this problem arises ....
nish
17th July 2009, 06:05
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..:)
wagmare
17th July 2009, 06:32
the problem arise here ..
this graphicsItem CentralItem has an ability to add proxywidgets ... and its code
CentralItem::CentralItem(const QRectF &rect, const QBrush &brush, QWidget *embeddedWidget)
: QGraphicsRectItem(rect),
brush(brush)
{
if(embeddedWidget){
proxyWidget = new QGraphicsProxyWidget(this);
proxyWidget->setFocusPolicy(Qt::StrongFocus);
proxyWidget->setWidget(embeddedWidget);
proxyWidget->setPos(5, 5);
}
}
void CentralItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
painter->setPen(Qt::NoPen);
painter->setBrush(QColor(0, 0, 0, 65));
painter->drawRoundRect(rect().translated(2, 2));
painter->setPen(QPen(Qt::black, 1));
painter->setBrush(brush);
painter->drawRect(rect());
}
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
wagmare
17th July 2009, 07:29
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 ...
xtfllbl
17th July 2009, 09:07
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.
void MyWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
paintXXXX(QPainter *);
wagmare
17th July 2009, 10:31
=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
ProxyBug::ProxyBug(QWidget *parent) : QDialog(parent)
{
QVBoxLayout *l = new QVBoxLayout( this );
QGraphicsView * group = new QGraphicsView;
QGraphicsScene * scene = new QGraphicsScene;
group->setScene(scene);
QGraphicsView * group2 = new QGraphicsView;
QGraphicsScene * scene2 = new QGraphicsScene;
group2->setScene(scene2);
group->scene()->addWidget(group2);
QLineEdit * lineEdit = new QLineEdit;
group2->scene()->addWidget(lineEdit); // this one crashing *
l->addWidget(group);
setLayout( l );
}
the group2 is try to embed another widget where group2 itself is embedded by group ...
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.