作者: 一去、二三里
个人微信号: iwaleon
微信公众号: 高效程序员
在 Scene 中添加 QGraphicsItem 后,当选中该 item 时,会看到边缘区域出现虚线,感觉不太美观。下面,我们来讲解如何去掉虚线并自定义选中样式。
默认样式
以椭圆为例,其它如:矩形、多边形等 item 类似。
// 构建一个椭圆
QGraphicsEllipseItem *pItem = new QGraphicsEllipseItem();
// 设置可选中、可移动
pItem->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);
// 设置样式(画笔 - 边框色 画刷 - 背景色)
QPen pen = pItem->pen();
pen.setWidth(2);
pen.setColor(QColor(0, 160, 230));
pItem->setPen(pen);
pItem->setBrush(QColor(247, 160, 57));
// ......
要出现选中效果,需