Unsolved QGraphicsView custom polygon button item
-
I'd like to add QPushButtons that are shaped like a polygon to my QGraphicsView.
Is this possible and if so, how?They need to be able to respond to a mouse press.
-
You dont need the
QPushButton
class for this...If you want to use your existing polygon items, you can make them clickable and react on mousePressEvent.https://doc.qt.io/qt-5/qgraphicsitem.html#mousePressEvent
Anyway, you can change the painter from your
QPushButton
derived class to make it look like a polygon...but if you want to click your GraphicsView-Items, I would go with the first option. -
@Pl45m4 So just create a custom QGraphicsPolygonItem and overwrite the mousepressevent?
-
Depends on your existing GraphicItems (I guess they have a custom type, no standard Qt-class objects?)
Something like this might work for you:
void MyPolygonShape::mousePressEvent(QGraphicsSceneMouseEvent *event) { qDebug() << "Hello, it's me"; // Do something here QGraphicsItem::mousePressEvent(event); }