PDA

View Full Version : Creating a widget on a QGraphicsView



maverick_pol
8th August 2007, 16:26
Hi guys,

I would like to paint a transparent widget(with crossPattern) on the QGraphicsView. I create a widget with QGraphicsView as its' parent, but nothing happens. While moving on the view I can't move on the exact rectangle where I specify the widget, but I can't see it. What is more I do not want that to happend; the widget should not accept any focus etc.

Here is a piece of code,



QWidget* panel;
panel = new QWidget(m_view);//m_view is the QGraphicsView
panel->setPaletteBackgroundColor(Qt::red);
panel->setFixedHeight(100);
panel->setFixedWidth(100);
panel->setBackgroundColor(Qt::red);
panel->setPaletteForegroundColor(Qt::red);
panel->setVisible(true);
panel->show();


How to make the widget visible?
How to force the widget to ignore any focus/mouseOver/mouseMove events?

Maverick

marcel
8th August 2007, 16:31
How to make the widget visible?

Since there isn't any layout to manage the widget's position and size, you have to do it manually, with move() or setGeometry().
You should move it in the desired position above the graphics view.



How to force the widget to ignore any focus/mouseOver/mouseMove events?

Disable the widget. It won't receive any mouse or keyboard events.

maverick_pol
9th August 2007, 11:43
Hi,

Thanks for advice, but still I do not see my widget. There is 'something transparent" on or under the widget, but I do not see it.

Maverick

marcel
9th August 2007, 14:37
You create the widget with the gv as parent. If you accidentally position this widget outside the bounds of the parent it will get clipped( you won't see it at all ).
So, double check you give the correct coordinates( try (0,0)).

Or, to make sure everything is ok with the widget and it can be seen, create it with a NULL parent and give it some position. It should appear at that position.

Regards

Gopala Krishna
9th August 2007, 18:54
Hi guys,
How to make the widget visible?
May be you should use m_view->viewport() as the parent of your widget.


How to force the widget to ignore any focus/mouseOver/mouseMove events?
Maverick
You can follow Marcel's idea. You can also install event filter which ignores all the events so that you can have enabled look, yet ignore the events.