PDA

View Full Version : QTextEdit on top of QGraphicsView, not QGraphicsScene



genjix
30th October 2010, 22:20
I have a QGraphicsView and want to add a QTextEdit on top of that, which resizes with the whole window. I parent it to the view, instead of the scene since the text needs to remain the same size.

5413
http://www.qtcentre.org/attachment.php?attachmentid=5413&d=1288469631


def resizeEvent(self, event):
# .....
winSize = self.contentsRect().size()
winw, winh = winSize.width(), winSize.height()
self.chat.resize(winw*0.5, winh*0.5)
self.chat.move(10,winh*0.5)


At the moment I resize it manually in the resizeEvent, but it's ugly since when you resize it updates and when scrollbars appear, it becomes transparent and I don't know how to turn it off.

How should I be doing this?

It's as if the widget has no 'sense' of the size of the window. If I could attach another widget to the window layered on top of the QGraphicsView below then this could be easily be solved by using layouts.

window.setWidget(QGraphicsScene); window.setWidget2(interactableGui)

That sort of thing ;)

wysota
30th October 2010, 23:10
I parent it to the view, instead of the scene since the text needs to remain the same size.
Eeem... would you care to explain what you mean by this?

jamie721
31st October 2010, 14:26
Ok im not sure this will help but i thought i should say i think the QGraphicsScene is just a collection of data with accessors and mutators (methods) no visual element. the graphics view is the widget that shows the scene if you get what i mean.


if i am wrong feel free to tell me as i am learning to.

genjix
31st October 2010, 14:56
If you parent it to the scene, then when you resize the window (and hence the view), the text will get smaller (and the box as a whole).

If you parent it to the view, then the whole box gets smaller with the text remaining the same size. Although then I am needing to resize the box manually inside resizeEvent since it seems to have no sense of it's parent's size.

genjix
2nd November 2010, 16:20
someone told me I have to use QGraphicsLayout. Here's what was said on the ML for others:

Well for a start you never mentioned that you were using QGraphicsView. In
fact you specifically said "widget".

Secondly, you can still use a QGraphicsLayout subclass. In this case set the
layout on a parent QGraphicsWidget rather than a QWidget.

This will *NOT* rescale your content but will only alter the size of your
QGraphicsWidget. I do this all of the time so I know that it works.

If you can still not get this to work please post a small *compilable* example
that shows the problem and we can help to modify it to make it work.

Cheers,

Sean

wysota
2nd November 2010, 17:04
I'm still not sure I understand what you mean (resizing the window doesn't cause any resizing of any of the items on its own, you have to implement it yourself) but I think that you might want to set the ItemIgnoresTransformations flag on the text edit item.