I'm developing a class that must contain like "products for sale list" in the form of graphics (QPixmap). So, I've chose QGraphicsView (for a similiar situation, in the past I've used QScrollArea and a QGridLayout to manage widgets buts is slow when you use to many widgets).
How many widgets are there?
What I plan to do is: having a way to arrange QPixmaps items inside QGraphicsView, so my question is: Do I need a layout to handle pixmaps in a easy way? Having in mind that items can be added and deleted so I must re-arrange items.
One easy way is to use QGraphicsWidget and QGraphicsLayout. If you want to use QGraphicsPixmapItem then you have take care to layout yourself.
I've reading how QGraphicsViews works, the scene and such, but I don't have clear how to work with a layout and pixmaps items inside this.
Can anyone supply a small example code?
This is an example to use QGraphicsWidget
int main(int argc, char *argv[])
{
QGraphicsWidget * widget = new QGraphicsWidget;
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
for(int i = 0; i < 10; i++)
{
label
->setPixmap
(QPixmap("C:/image.jpg"));
QGraphicsWidget * w = scene.addWidget(label);
layout->addItem(w);
}
widget->setLayout(layout);
scene.addItem(widget);
view.setScene(&scene);
view.show();
return a.exec();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsView view;
QGraphicsScene scene;
QGraphicsWidget * widget = new QGraphicsWidget;
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
for(int i = 0; i < 10; i++)
{
QLabel * label = new QLabel;
label->setPixmap(QPixmap("C:/image.jpg"));
QGraphicsWidget * w = scene.addWidget(label);
layout->addItem(w);
}
widget->setLayout(layout);
scene.addItem(widget);
view.setScene(&scene);
view.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks