PDA

View Full Version : QCanvasItem as QWidget



sanjay
8th July 2008, 09:02
Hi All,
Is it possible to to have a custom QCanvasItem which can act as a widget as well?
For e.g. it can generate signals like 'clicked'.

~ A newbie

jacek
8th July 2008, 23:41
With a little work you can make QCanvasItem emit clicked() signal. First you have to make QCanvasView detect mouse clicks. The rest is easy.

sanjay
9th July 2008, 15:18
Thanks Jacek.
As I could understand from your response, I am capturing mouse clicks on the QCanvasItem. This I am using to generate a new QCanvas/view which shows details (some more diagrams) for the object represented by QCanvasItem.
Is this a right appoach?

jacek
9th July 2008, 15:30
As I could understand from your response, I am capturing mouse clicks on the QCanvasItem.
No, QCanvasItem can't capture mouse clicks --- only QCanvasView can do that. You just have to forward the information about mouse click from the canvas view to the canvas or canvas item.

In order to allow canvas items to emit signals you have to turn them into QObjects. If you have a lot of such items, it might not be the best approach. So instead you can consider emitting the signal from the canvas or canvas view.