I have been using Qt Creator for almost a month now. I hope this is not a silly question because it bugged me for a long time.
I want to achieve:
- create many different items(let's say 20 per sec) in
QGraphicsScene
.
- create many different items(let's say 20 per sec) in
- use one single class for all these items
- mark all these items, delete or hide them when a signal is triggered.
After trying a lot of methods, the best way I see is to use QGraphicsItemGroup
. I tried to group all of them into a QGraphicsItemGroup
. But after adding an item into a group, the item refuses to show on the scene any more, no matter what functions I use from library.
Is there something which I did wrongly in using the QGraphicsItemGroup
? Or are there any other better apporaches?
Looking forward to anyone's help. Really appreciated.
Followed is a structure of my code:
// ......
QGraphicsItemGroup *myItemsGroup = new QGraphicsItemGroup
timer->start(100);
connect(timer,SIGNAL(timeout()),this,SLOT(draw_trail()));
// ......
void MyFunction::draw_trail()
{
Trail_item *new_item = new Trail_item;
scene->addItem(new_item);
new_item->setX(COPX-7);
new_item->setY(COPY-7);
new_item->setZValue(5);
/*
then I started trying add to group
//myItemsGroup->addToGroup(new_item)
after adding this line, the item vanishes.
*/
}
(note: trail_item
is a item class I created. Since it is a loop, I don't know how to change *new_item
pointer name, so all items have the same name.)