U形聚线在QT中选择其他聚线时遇到麻烦
我有qgraphicsview
,其中包含许多矩形和各个构造。我的观点看起来像这样。
如果我单击位置A,B,C,D橙色polyline选择。如果我尝试在u形橙色多线线内选择层次,那么它们永远不会被选中。仅选择橙色的多线线。
如果我单击位置e,f,g a蓝色多线线将选择。我不能选择这些U形polyline内部的任何东西。如果我尝试在这些U形质量线中选择任何内容,则仅选择U形型层。
设计中有许多多聚元素和矩形。但是这个问题仅带有u形状的多聚线。 粒线(不是u形成的,并且不在u形内的polyline内部。
其他多 如果单击它们,它会在该项目周围创建一个虚线的矩形。因此,在U Shape Polyline中,它也会产生一个虚线的矩形,如果您单击该矩形,则只选择了该多线线。 在Paint()方法中,我已经更改了QT的默认选择方法,但是我认为仍然存在一个问题,它不允许我选择其他polylines。
void myPoly::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
auto copied_option = *option;
copied_option.state &= ~QStyle::State_Selected;
auto selected = option->state & QStyle::State_Selected;
QGraphicsPathItem::paint(painter, &copied_option, widget);
if (selected) {
painter->save();
painter->setBrush(Qt::NoBrush);
painter->setPen(QPen(option->palette.windowText(), 0, Qt::SolidLine));
painter->drawPath(shape());
painter->restore();
}
}
我尝试使用setBoundingRegiongranularity(1),但它不起作用。
通过Paint()选择QGraphicSitem是不完整的吗?还是此问题与Paint()无关,而与其他一些问题有关,例如放置多聚线?
I have QGraphicsView
which contains many rectangles and polylines. My view looks something like this.
If I click on position A , B, C , D orange color polyline gets selected. If I try to select polyline inside U - shaped orange polyline, they never get selected. Only the orange color polyline gets selected.
If I click on position E, F, G a blue color polyline gets selected. I can not select anything which is inside of these U - shaped polylines. If I try to select anything inside these U - shaped polylines, only U shaped polyline gets selected.
There are many polylines and rectangles in the design. But this problem arises with only U - shaped polylines. Other polylines ( which are not U shape, and which are not inside U - shaped polylines get selected properly. )
There is a by default Qt's selection method of any QGraphicsItem. If you click on them, it creates a dotted rectangle around that item. So, in U shape polylines, it also creates a dotted rectangle and if you click inside that rectangle, only that polyline gets selected.
In paint() method I have changed that default selection method of Qt, but I think there is still a problem which is not letting me to select other polylines.
void myPoly::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
auto copied_option = *option;
copied_option.state &= ~QStyle::State_Selected;
auto selected = option->state & QStyle::State_Selected;
QGraphicsPathItem::paint(painter, &copied_option, widget);
if (selected) {
painter->save();
painter->setBrush(Qt::NoBrush);
painter->setPen(QPen(option->palette.windowText(), 0, Qt::SolidLine));
painter->drawPath(shape());
painter->restore();
}
}
I tried with setBoundingRegionGranularity(1) but it did not work.
Selection of QGraphicsItem through paint() is incomplete ? Or this problem is not related to paint() but related to some other problem like placing of polylines ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论