shock
26th November 2011, 18:38
Hey Guys,
I subclassed QGraphicsView and an QGraphicsPixmapItem...
What i want: I want to add a Pixmap to the GraphicsView and resize it (if the pixmap does not have it's desired maximum size) on resizing the GraphicsView..
What i receive: an unhandled exception in QPaintDevice::paintingActive()
inline bool QPaintDevice::paintingActive() const
{ return painters != 0; } // seems i get the exception here
BackgroundItem::BackgroundItem(const QPixmap &pixmap)
: QGraphicsPixmapItem(pixmap)
{
myOriginalPixmap = pixmap;
}
QPixmap BackgroundItem::getOriginalPixmap(){
return myOriginalPixmap;
}
void FloorPlanGraphicsView::init()
{
canvas = new QGraphicsScene(this);
//scene->setSceneRect(0,0,this->geometry().width(),this->geometry().height();
setScene(canvas);
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
}
void FloorPlanGraphicsView::setFloorPlan(const QPixmap &image){
BackgroundItem *backImg = new BackgroundItem(image);//.scaled(geometry().width(),geometry().height(),Qt: :KeepAspectRatio));
scene()->addItem(backImg);
backImg->setPos(0,0);
backImg->setZValue(0);
backImg->setPixmap(image.scaled(geometry().width(),geometry ().height(),Qt::KeepAspectRatio));
}
void FloorPlanGraphicsView::resizeEvent(QResizeEvent *event){
scene()->setSceneRect(0,0,this->geometry().width(),this->geometry().height());
QList<QGraphicsItem*> graphicItems = scene()->items();
for (int i = 0; i < graphicItems.size(); ++i){
if (graphicItems.at(i)->type() == FloorPlanGraphicsView::BackgroundType){
BackgroundItem *myBackItem = qgraphicsitem_cast<BackgroundItem*>(graphicItems.at(i));
if(this->geometry().width() <= myBackItem->getOriginalPixmap().size().width() && this->geometry().height() <= myBackItem->getOriginalPixmap().size().height())
// i get the error immediately here on resize!
myBackItem->setPixmap(myBackItem->getOriginalPixmap().scaled(this->geometry().width(),this->geometry().height(),Qt::KeepAspectRatio));
else
myBackItem->setPixmap(myBackItem->getOriginalPixmap());
}
}
}
The invocation to setFloorPlan() looks like the following:
ui.floorPlan->setFloorPlan(QPixmap::fromImage(QImage::fromData(q uery.value(0).toByteArray())));
Do i have to reimplement a paint() function or something similar here?
Anbody any idea for me?
I subclassed QGraphicsView and an QGraphicsPixmapItem...
What i want: I want to add a Pixmap to the GraphicsView and resize it (if the pixmap does not have it's desired maximum size) on resizing the GraphicsView..
What i receive: an unhandled exception in QPaintDevice::paintingActive()
inline bool QPaintDevice::paintingActive() const
{ return painters != 0; } // seems i get the exception here
BackgroundItem::BackgroundItem(const QPixmap &pixmap)
: QGraphicsPixmapItem(pixmap)
{
myOriginalPixmap = pixmap;
}
QPixmap BackgroundItem::getOriginalPixmap(){
return myOriginalPixmap;
}
void FloorPlanGraphicsView::init()
{
canvas = new QGraphicsScene(this);
//scene->setSceneRect(0,0,this->geometry().width(),this->geometry().height();
setScene(canvas);
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
}
void FloorPlanGraphicsView::setFloorPlan(const QPixmap &image){
BackgroundItem *backImg = new BackgroundItem(image);//.scaled(geometry().width(),geometry().height(),Qt: :KeepAspectRatio));
scene()->addItem(backImg);
backImg->setPos(0,0);
backImg->setZValue(0);
backImg->setPixmap(image.scaled(geometry().width(),geometry ().height(),Qt::KeepAspectRatio));
}
void FloorPlanGraphicsView::resizeEvent(QResizeEvent *event){
scene()->setSceneRect(0,0,this->geometry().width(),this->geometry().height());
QList<QGraphicsItem*> graphicItems = scene()->items();
for (int i = 0; i < graphicItems.size(); ++i){
if (graphicItems.at(i)->type() == FloorPlanGraphicsView::BackgroundType){
BackgroundItem *myBackItem = qgraphicsitem_cast<BackgroundItem*>(graphicItems.at(i));
if(this->geometry().width() <= myBackItem->getOriginalPixmap().size().width() && this->geometry().height() <= myBackItem->getOriginalPixmap().size().height())
// i get the error immediately here on resize!
myBackItem->setPixmap(myBackItem->getOriginalPixmap().scaled(this->geometry().width(),this->geometry().height(),Qt::KeepAspectRatio));
else
myBackItem->setPixmap(myBackItem->getOriginalPixmap());
}
}
}
The invocation to setFloorPlan() looks like the following:
ui.floorPlan->setFloorPlan(QPixmap::fromImage(QImage::fromData(q uery.value(0).toByteArray())));
Do i have to reimplement a paint() function or something similar here?
Anbody any idea for me?