PDA

View Full Version : How to use a QPolygon as a Pushbutton?



Manish.S
6th December 2010, 03:56
Hi

I have created a polygon using PolygonF class in a Graphics Scene. Now i want to use that polygon as a button/push button to perform or trigger some event.

I am not able to figure out how can I use the full area of the polygon as a button.

Any help is welcome.

scene = new QGraphicsScene(0, 0, 730, 500, this);

view = new QGraphicsView(scene, this);

item = view->itemAt(130, 50);

QPolygonF poly1;

poly1 << QPointF(110, 80) << QPointF(170, 80) << QPointF(200, 130) << QPointF(170, 180) << QPointF(110, 180) << QPointF(80, 130) ;

scene->addPolygon( poly1 , QPen(brush1, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin), QBrush(QColor(Qt::white)));

QLinearGradient linearGradient(0, 0, 100, 100);

linearGradient.setColorAt(0, QColor(140, 140, 140, 255));

scene->setBackgroundBrush(linearGradient);

view->setScene(scene);

view->show();

Thanks and Regards

Manish.S

zgulser
6th December 2010, 07:18
Hi,

Maybe you can try out implementing QPushButton first and then making it's shape as a polygon. I mean try to implement something like the following;



MyCustomPushButton : public QPushButton {

...
void drawControl(..) // reimplement this
}

wysota
6th December 2010, 08:49
You need to reimplement mouse events for your scene item.

Manish.S
6th December 2010, 10:48
Hi

Thanks for the replies. I would try and implement these.

But i have a doubt.
Will a mouse event work on a touch screen as well?

Thanks and Regards

Manish.S

wysota
6th December 2010, 10:57
Will a mouse event work on a touch screen as well?
Yes. The touch screen really emulates a mouse.