PDA

View Full Version : How to send the QGraphicsItem to the background of QGraphicsView



battena
22nd November 2012, 12:50
Goal is to send few QGraphicsItem's to the QGraphicsView's background so that
itemAt() function will not detect the items are in background on mouse click position and other mouse events are ignored.

I understood that I can not do it with QGraphicsView::drawBackground(painter,rectf),
some info from Qt Assistant that I need to try with QGraphicsView::drawItems(i.e. itemlayer), but who will send items list to this function? some example would be great, even if I send items to the itemlayer will the items detected by the function call itemAt()?

Thanks/Srinivas

wysota
22nd November 2012, 13:20
Can't you just hide the item?

battena
22nd November 2012, 14:13
Thanks for your quick ans.

I could hide using "setVisible(false)", intention is to paint the item and make visible and disable events & actions
I tried with SetEnabled(false) but it did not work.

wysota
22nd November 2012, 14:17
Why exactly do you want to do all that?

battena
22nd November 2012, 14:30
good question.

I am doing as follows...

I have two applications..
In first application I have a QGraphicsView attached with QGraphicsScene, where I do some design like draw border based on vertical & harizantal values.
Also I placed some text graphics item at the top say 'Author "xxxx"'. Now I have to steam this info into a file using QDataStream.

In second application I need to load the stream and create the saved objects like QGraphcisRectItem & QGraphicsTextItem with values and display them in the background. what ever we create further items shall be on top of them.

I hope I answered to you question.

wysota
22nd November 2012, 15:09
I do not see how this is related to wanting an item to ignore mouse events :)

battena
22nd November 2012, 15:30
I am creating selection handles for the newly created graphic item there I have a constraint that I should not create a selection handle if I find a item below to it with the function itemAt(pos).
Since those items are not send to the background they are caught by the itemAt() function.

this is the use case.

wysota
22nd November 2012, 15:34
Since those items are not send to the background they are caught by the itemAt() function.
Ok but WHAT items?

battena
22nd November 2012, 15:37
sorry!

as I said in the first application I have saved some graphic items like rect, text.
In the second application I have loaded the saved items.
and then I draw a new rectangle graphic item above to them.

wysota
22nd November 2012, 15:45
Yes, and so? Please do not focus your description on the itemAt() method but rather say what exact behaviour you want to achieve globally. I'm assuming you know about the z-order of items and you can determine which object is "above" and which is "below" but I totally fail to see WHAT item should have its mouse events ignored and WHY (especially that it won't affect what itemAt() returns).