如何删除 QGraphicsItem 周围的边框
How to remove border around QGraphicsItem when selected?
非常基本的问题,但我无法通过谷歌找到解决方案。在 QT 中,当选择图形项时,它周围有一个边框。我想知道如何将此边框设置为不可见。谢谢。
没有接口可以禁用内置 QGraphicsItems 的选择边框的绘制。我能想到的唯一方法是从内置项目派生您自己的项目并覆盖 paint()
函数:
void MyRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QStyleOptionGraphicsItem myOption(*option);
myOption.state &= ~QStyle::State_Selected;
QGraphicsRectItem::paint(painter, &myOption, widget);
}
它没有经过测试,但基本上你复制了传递的选项,并在将其传递给实际paint()
之前清除了选择状态标志。
如果你的QGraphicsItem派生自QAbstractGraphicsShapeItem,那么你只需禁用它的笔,例如:
myShape->setPen(Qt::NoPen);
对于那些试图使用python弄清楚的人:
def paint(self, painter, option, a):
option.state = QStyle.State_None
return super(MyClassName, self).paint(painter,option)
相关文章:
- 将QGraphicsItem的移动区域限制在多边形区域内
- 变量周围的堆栈'...'已损坏
- 运行时检查失败 #2 变量"A"周围的堆栈已损坏
- OpenCV代码不会检测人脸的数量,也不会在脸周围放一个圆圈
- 为什么我的 VS 代码调试器在我的C++代码周围弹跳?
- 运行时检查失败 #2 - 变量"e"周围的堆栈已损坏。发生
- 如何更改 QGraphicsItem 对象的颜色?
- 变量周围的堆栈'sortArray'已损坏
- 需要帮助编写 for 循环以在字符串周围创建边框
- 使函数参数默认为周围范围
- 变量周围的堆栈'folderPath'已损坏
- 线程构造函数周围的可变参数模板包装器无法编译
- 如何检查二维数组上的周围数字?
- 运行时检查失败 #2 - 变量周围的堆栈'...'已损坏
- 组合的QGraphicsItem未检测到子项上的单击
- 如何将QGraphicsItem QList保存到文件中,然后读取它?Qt c++
- 如何在屏幕周围生成随机像素
- 访问周围类中迭代器的私有值
- 运行时检查失败 #2 - 变量"l1"周围的堆栈已损坏
- 如何删除 QGraphicsItem 周围的边框