PDA

View Full Version : QGraphicsScene - Adding graphics into it from 3rd party library



augusbas
7th June 2012, 08:29
Hello all,

We are working on QGraphicsScene and all the graphics to it is added as items.

And we get some other graphics data from the 3rd party library also and we need to insert the same into the graphics scene.

3rd party provides two options on getting its graphics data

1) It will draw the graphics if we provide the window ID to its classes. But QGraphicsScene doesn't have winID,only QGraphicsView is having WinID

(or)

2) It provides a bitmap where we can read and convert as pixmap and add as item to Graphics scene . By using the second option the cpu load is more.

Please advise how can we achieve this with the first method (or) best way of bringing the graphics into it.

wysota
7th June 2012, 09:53
In both cases you end up with a bitmap of the item hence you can prerender all the bitmaps outside Graphics View (e.g creating a fake window that is never shown) and then import them into the framework as QGraphicsPixmapItem instances. The beauty of Graphics View is the ability to transform the view and I doubt you'll get that possibility with method 1 of the external framework. Of course all depends on your particular usecase.

augusbas
7th June 2012, 12:28
In both cases you end up with a bitmap of the item hence you can prerender all the bitmaps outside Graphics View (e.g creating a fake window that is never shown) and then import them into the framework as QGraphicsPixmapItem instances. The beauty of Graphics View is the ability to transform the view and I doubt you'll get that possibility with method 1 of the external framework. Of course all depends on your particular usecase.

Dear Wysota,

Thank you for your reply..

I have referred your sample code below from this forum and i tried to insert the graphics from 3rd party library what i am using (using graphics view winID) . The Graphics is of 32bit Radar.

Upon insert the radar is inserted to the window. Graphics Items are always on top of the radar. Is there some way i can change the graphics item as overlay and underlay.

Please advise.


#include <QtGui>
#include <QPropertyAnimation>
#include <QDebug>

class RectItem : public QObject, public QGraphicsRectItem {
Q_OBJECT
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
public:
RectItem(const QRectF &rect, const QPen &pen, const QBrush &brush) : QObject(), QGraphicsRectItem(rect){
setPen(pen);
setBrush(brush);
}
};

#include "main.moc"

int main(int argc, char **argv){
QApplication app(argc, argv);
QGraphicsView view;
view.setAttribute(Qt::WA_TranslucentBackground);
view.viewport()->setAttribute(Qt::WA_TranslucentBackground);
QGraphicsScene scene(QRectF(0,0,1000,800));
view.setScene(&scene);
RectItem *rect = new RectItem(QRectF(0,0,200,100), QPen(QColor(255,0,0,0)),QColor(0,0,255,127) ); //Qt::red Qt::blue
scene.addItem(rect);
//rect->setOpacity(0.5);
//rect->setZValue(9);
RectItem *rect1 = new RectItem(QRectF(0,0,200,100), QPen(QColor(255,0,0,0)),QColor(255,0,0,255) ); //Qt::red Qt::blue
scene.addItem(rect1);
QPropertyAnimation *anim = new QPropertyAnimation(rect, "pos");
anim->setDuration(50000);
anim->setStartValue(scene.sceneRect().topLeft());
anim->setEndValue(scene.sceneRect().bottomRight());
anim->start();
QPropertyAnimation *anim1 = new QPropertyAnimation(rect1, "pos");
anim1->setDuration(50000);
anim1->setStartValue(scene.sceneRect().topRight());
anim1->setEndValue(scene.sceneRect().bottomLeft());
anim1->start();

qDebug() << "In Code \n" ;
view.show();
return app.exec();
}

wysota
7th June 2012, 15:33
I don't see how this code is relevant to anything you are doing...