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:aintingActive()
{ return painters != 0; } // seems i get the exception here
inline bool QPaintDevice::paintingActive() const
{ return painters != 0; } // seems i get the exception here
To copy to clipboard, switch view to plain text mode
BackgroundItem
::BackgroundItem(const QPixmap &pixmap
){
myOriginalPixmap = pixmap;
}
QPixmap BackgroundItem
::getOriginalPixmap(){ return myOriginalPixmap;
}
BackgroundItem::BackgroundItem(const QPixmap &pixmap)
: QGraphicsPixmapItem(pixmap)
{
myOriginalPixmap = pixmap;
}
QPixmap BackgroundItem::getOriginalPixmap(){
return myOriginalPixmap;
}
To copy to clipboard, switch view to plain text mode
void FloorPlanGraphicsView::init()
{
//scene->setSceneRect(0,0,this->geometry().width(),this->geometry().height();
setScene(canvas);
}
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());
}
}
}
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());
}
}
}
To copy to clipboard, switch view to plain text mode
The invocation to setFloorPlan() looks like the following:
ui.
floorPlan->setFloorPlan
(QPixmap::fromImage(QImage::fromData(query.
value(0).
toByteArray())));
ui.floorPlan->setFloorPlan(QPixmap::fromImage(QImage::fromData(query.value(0).toByteArray())));
To copy to clipboard, switch view to plain text mode
Do i have to reimplement a paint() function or something similar here?
Anbody any idea for me?
Bookmarks