I think you'll need to create a subclass and reimplement virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) to draw the selection yourself. In order to prevent rendering of the default selection rect, you'll need to clear the QStyle::State_Selected flag from option argument:
// header, QGraphicsItemBaseClass should be the one you want to subclass (QGraphicsPixmapItem,QGraphicsEllipseItem,...)
class MyGraphicsItem:public QGraphicsItemBaseClass{
public:
//...
// .cpp
opt.
state &= ~
QStyle::State_Selected;
// clears the default selection marker QGraphicsItemBaseClass::paint(painter,&opt,widget); // render graphics item without selection rect
//...
}
// header, QGraphicsItemBaseClass should be the one you want to subclass (QGraphicsPixmapItem,QGraphicsEllipseItem,...)
class MyGraphicsItem:public QGraphicsItemBaseClass{
public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
//...
// .cpp
void MyGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
QStyleOptionGraphicsItem opt = *option;
opt.state &= ~QStyle::State_Selected; // clears the default selection marker
QGraphicsItemBaseClass::paint(painter,&opt,widget); // render graphics item without selection rect
//...
}
To copy to clipboard, switch view to plain text mode
You can test for the QStyle::State_Selected flag in paint method to render the selection your way:
if( option
->state
& QStyle::State_Selected ){ //... your selection rendering method here
}
}
void MyGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
if( option->state & QStyle::State_Selected ){
//... your selection rendering method here
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks