PDA

View Full Version : Draw button(similer to QPushButton) using the QPainter.



pastispast
22nd July 2010, 20:47
Hi Friends,

I am implementing some graphics related application(like a radar view). In the view I have to draw the real time data on the screen. There are some attribute of that data (like status as progress bar, tool tip, image, mouse event).

Hence I am:

- First implementing the basic screen using the paint class. In the paint I am using "setViewport" and "setWindow" for re-size consideration.
- Then I am using the custom button (QPushButton) for the attributes.

First I want to ask, "is this the correct approach" or there is any thing in the paint class that provide me click functionality. If I want to go with the paint class then it will be easy to represent the live data, but due to live data attribute I can not go for it.

Please suggest me for the missing functionality or better approach.

tbscope
22nd July 2010, 21:58
I would probably do this another way. I would use a QGraphicsView, create some custom items for the radar and then use a qgraphicsproxywidget for the pushbutton or checkboxes etc...

pastispast
23rd July 2010, 19:11
I would probably do this another way. I would use a QGraphicsView, create some custom items for the radar and then use a qgraphicsproxywidget for the pushbutton or checkboxes etc...

Hi "tbscope"...Thanks to suggest the above approach. I feel this is the better approach to do the above condition. Now I am using this approach.

But now after putting the controls over the QGraphicsView, I am getting the problem while resizing:

- I am using resizing event for resizing the QGraphicsView:
QGraphicsView::resizeEvent(event);
fitInView(scene->sceneRect(), Qt::KeepAspectRatio);

- But during the resize controls are not synchronize with the QGraphicsView.

What can be the cause of this?

I have one more doubt that can I use QPainter drawing in "QGraphicsView".

Once again thanks for the reply.

tbscope
24th July 2010, 20:48
- I am using resizing event for resizing the QGraphicsView:
QGraphicsView::resizeEvent(event);
fitInView(scene->sceneRect(), Qt::KeepAspectRatio);

- But during the resize controls are not synchronize with the QGraphicsView.

What can be the cause of this?
What do you mean with synchronize? Do you mean that all the objects jump around?


I have one more doubt that can I use QPainter drawing in "QGraphicsView".
Sure, but it's pointless as the view is a container for items that are drawn on top of it.
The correct way to do this is create a custom QGraphicsItem and implement the paint function. See the QGraphicsItem documentation.