I am trying to use hide() show() or setVisible(false) function with QGraphicsRectItem objects. I can display them on the scene but no way I can do anything to hide them from screen. I have initialised them in the following code :
rectItems = new QVector<QGraphicsRectItem *>();
for (int raw=0;raw<this->qElementsHeight;raw++){
for(int column=0;column<this->qElementsWidth;column++){
QRectF rectF
( raw
*48, column
*48,
48,
48 );
rect->setPen(pen);
rectItems->push_back(rect);
rectItems->last()->setVisible(false);
this->addRect(rectItems->last()->rect(),pen);
}
}
rectItems = new QVector<QGraphicsRectItem *>();
for (int raw=0;raw<this->qElementsHeight;raw++){
for(int column=0;column<this->qElementsWidth;column++){
QRectF rectF( raw*48, column*48, 48, 48 );
QGraphicsRectItem *rect = new QGraphicsRectItem(rectF);
rect->setPen(pen);
rectItems->push_back(rect);
rectItems->last()->setVisible(false);
this->addRect(rectItems->last()->rect(),pen);
}
}
To copy to clipboard, switch view to plain text mode
then tried to use hide() in a slot function:
for (int c=0;c<rectItems->count();c++){
if(bGrid) {
//temp->setVisible(true);
//temp->show();
rectItems[0].at(c)->setVisible(true);
}
else {
//temp->setVisible(false);
//temp->hide();
rectItems[0].at(c)->setVisible(false);
}
}
for (int c=0;c<rectItems->count();c++){
QGraphicsRectItem *temp =rectItems->at(c);
if(bGrid) {
//temp->setVisible(true);
//temp->show();
rectItems[0].at(c)->setVisible(true);
}
else {
//temp->setVisible(false);
//temp->hide();
rectItems[0].at(c)->setVisible(false);
}
}
To copy to clipboard, switch view to plain text mode
none of it hides the rectangles in the scene. Is there a way of hiding them ?
Bookmarks