如何在QT中解开隐藏的QgraphicTem?
我有qgraphicsview
,它具有多个qgraphicsItem
'的s。 在QgraphicsItem中,我很少有矩形
和一些polylines
。各矩形附着。
我有一个功能隐藏矩形
,其中我从视图中手动选择一些矩形,然后在右鼠标按钮上,有一个选项,例如hida rectangles
,它调用函数<代码>隐藏所选矩形的hideselectectRectangles()。
它的代码是:
void myClass::HideSelectedRectangles()
{
foreach(QGraphicsItem* currentItem, scene->selectedItems())
{
QGraphicsRectItem* rectItem = qgraphicsitem_cast<QGraphicsRectItem*>(currentItem);
if(rectItem )
{
rectItem ->hide();
rectItem ->setSelected(true); // In Refresh() scene->selectedItem() does not recognize this flag
}
}
}
一旦矩形隐藏,就会有一个刷新
按钮,希望带回所有隐藏的对象。
void myClass::Refresh()
{
foreach(QGraphicsItem* currentItem, scene->selectedItems())
{
QGraphicsRectItem* rectItem = qgraphicsitem_cast<QGraphicsRectItem*>(currentItem);
if(rectItem)
{
rectItem->show();
//QPen mPen;
//mPen.setWidth(1);
//mPen.setColor(QColor("blue"));
//rectItem->setPen(mPen);
rectItem->setSelected(false);
}
}
}
但是上面的代码不起作用。在scene-&gt; selectionItems()
找不到选定的项目。 如何使用scene-&gt; selectitems()
在refresh()?
中解开矩形?
我不想在refresh()中使用scene-&gt; tocke()
,因为我不想一次又一次地迭代整个scene
出于复杂性目的。
I am having QGraphicsView
, which has multiple QGraphicsItem
's.
In QGraphicsItem's, I am having few rectangles
and some polylines
. Polylines are attached to rectangles.
I have a feature Hide Rectangle
in which I manually select a few rectangles from view and then on the right mouse button, there is an option like Hide Rectangles
which calls the function HideSelectedRectangles()
which hides the selected rectangles.
Its code is :
void myClass::HideSelectedRectangles()
{
foreach(QGraphicsItem* currentItem, scene->selectedItems())
{
QGraphicsRectItem* rectItem = qgraphicsitem_cast<QGraphicsRectItem*>(currentItem);
if(rectItem )
{
rectItem ->hide();
rectItem ->setSelected(true); // In Refresh() scene->selectedItem() does not recognize this flag
}
}
}
Once Rectangles get hidden, there is a Refresh
button that expects to bring back all the hidden objects.
void myClass::Refresh()
{
foreach(QGraphicsItem* currentItem, scene->selectedItems())
{
QGraphicsRectItem* rectItem = qgraphicsitem_cast<QGraphicsRectItem*>(currentItem);
if(rectItem)
{
rectItem->show();
//QPen mPen;
//mPen.setWidth(1);
//mPen.setColor(QColor("blue"));
//rectItem->setPen(mPen);
rectItem->setSelected(false);
}
}
}
But above code does not work. At scene->selectedItems()
there is no selected item found.
How to unhide rectangle using scene->selectedItems()
in Refresh() ?
I do not want to use scene->items()
in Refresh() as I do not want to iterate over the whole scene
again and again for the complexity purpose.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论