Results 1 to 6 of 6

Thread: Editing QGrahpicsTextItem with QWidget

  1. #1
    Join Date
    Apr 2013
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Editing QGrahpicsTextItem with QWidget

    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?
    Last edited by infyar; 4th April 2013 at 08:10.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Editing QGrahpicsTextItem with QWidget

    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).
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Apr 2013
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Editing QGrahpicsTextItem with QWidget

    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?

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Editing QGrahpicsTextItem with QWidget

    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
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. #5
    Join Date
    Apr 2013
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Editing QGrahpicsTextItem with QWidget

    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.

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Editing QGrahpicsTextItem with QWidget

    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?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Replies: 1
    Last Post: 30th October 2010, 12:28
  2. Replies: 1
    Last Post: 16th September 2010, 15:57
  3. Replies: 1
    Last Post: 12th April 2010, 12:55
  4. Replies: 3
    Last Post: 1st April 2010, 23:56
  5. Replies: 1
    Last Post: 2nd May 2006, 21:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.