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.


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().

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


Need Your Help

How to call a Bash script from VBA (Excel)

macos bash vba excel-vba-mac

How can I run a bash file using VBA on MAC OSX