PDA

View Full Version : Editing QGrahpicsTextItem with QWidget



infyar
4th April 2013, 08:45
Good day everyone. I've been reading this forum for a while before posting this one, and it is quite useful, hope to get hints on my problem :)

What I'm trying to do is to edit QGraphicsTextItem subclass containing rich text with a widget. My goal is to create kind of a tool bar to edit rich text in an item which floats above QGraphicsTextItem while it is in edit mode and closes immidiately after editing is finished. The problem is that when I create a Widget it takes focus from item and interrupts editing. How can I prevent QGraphicsTextItem from loosing focus or quitting edit mode caused by focus loss? Currently QWidget is created in focusInEvent and destroyed in focusOutEvent, maybe I can somehow keep editing mode of Item by checking if at least one (Widget or Item) has focus?

Santosh Reddy
4th April 2013, 09:14
Are you looking for inplace editing? QGraphicsTextItem supports editing, you need to enable using setTextInteractionFlags()..

And if you want to edit using a QWidget, it would better to do it with modal QDialog (e.g. QInputDialog).

infyar
4th April 2013, 13:10
I've enabled editing, that is not the point. Modal dialog wont fit, what I'm trying to do looks like editing selected text in MS Word via tiny bar floating over selected text (there are several text alignment buttons, font size and font family pickers and so on), it becomes fully opaque when mouse hoovers over it and transparent when not. My problem is that when I create QWidget inside QGraphicsTextItem subclass and show() it, QGraphicsTextItem looses focus and editing stops (at least it looks like it stops because text cursor dissapears and dashed frame around QGraphicsTextItem becomes invisible, and focusOutEvent is called), how can I avoid interruption of editing process after I created QWidget and poped it up above the Item?

Santosh Reddy
4th April 2013, 13:36
So you want in place editing. I don't think you can avoid the QWidget from taking the focus away from the QGrpahicsView.

Instead try using QGraphicsWidget. Create this QGraphicsWidget and add the scene before hand and show/hide the QGraphicsWidget as when required focus in/out. That way I think QGraphcisView will have the focus and continue to pass it on the QGraphicsTextItem under editing

infyar
5th April 2013, 08:17
That is what I was aware of. In case of QGraphicsWidget (QGraphicsProxyWidget) my ToolWidgetEditor cannot leave the QGraphicsView area, and my QGraphicsScene is set as index widget inside QTableView, so it doesn't look and behave like in place editor in MS Word and looks quite strange for the user. I suppose the way I'm rtying to implement in place editing is wrong, so far my problem is not resolved.

Santosh Reddy
5th April 2013, 11:26
So you are looking for a tool bar which floats over all the widgets, are you using QToolBar, or QWidget for this?


...and my QGraphicsScene is set as index widget inside QTableView,...
Does that mean you have multiple QGraphicsViews and this tool bar should float over all of them?

BTW do QGrpahicsView and the ToolWidgetEditor share the same parent?