Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove border around QGraphicsItem when selected?

Pretty basic question but I couldn't find a solution through google. In QT when a graphics item is selected, there's a border around it. I was wondering how I can set this border to be invisible. Thanks.

like image 295
JustinBlaber Avatar asked Jun 11 '12 17:06

JustinBlaber


2 Answers

There's no interface to disable the drawing of the selection border for the build-in QGraphicsItems. The only way I can think of is derive your own items from the build-in ones and override the paint() function:

void MyRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    QStyleOptionGraphicsItem myOption(*option);
    myOption.state &= ~QStyle::State_Selected;
    QGraphicsRectItem::paint(painter, &myOption, widget);
}

It's not tested but basically you make a copy of option passed and clear the selection state flag before passing it to the actual paint().

like image 137
Stephen Chu Avatar answered Sep 25 '22 06:09

Stephen Chu


If your QGraphicsItem is derived from QAbstractGraphicsShapeItem then you can simply disable its pen, example:

myShape->setPen(Qt::NoPen);
like image 37
mirswith Avatar answered Sep 23 '22 06:09

mirswith