Results 1 to 19 of 19

Thread: Interactive text formatting in QGraphicsTextItem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2009
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Interactive text formatting in QGraphicsTextItem

    I've got a problem with interactive text formatting inside a QGraphicsTextItem (more correctly inside my own QGraphicsTextItem-derived class).

    I have created the same toolbar as in diagramscene example with five controls - two combos and three buttons - and implemented my own text formatting methods using QTextCursor to apply new formatting to selected text fragments only.

    The problem is that when I click on the toolbar on font or font size combo the item on the scene looses focus (and thus looses text selection) and formatting doesn't applies to the text. At the same time simple buttons (bold, italic etc) work OK. It seems that I've missed some option that prevents item from loosing its focus when the mouse pointer leaves the scene or something like this.

    Can anybody help me to solve this? Thanks in advance.

    PS. I've looked at textedit demo and found that it connects combos' activated() signals to custom slots. It this a solution to this problem? Is there a more advanced example (than the buggy diagramscene) on how to interactively format text inside QGraphicsTextItem?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Interactive text formatting in QGraphicsTextItem

    Try setting focus policy of those troublesome widgets to NoFocus.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2009
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Interactive text formatting in QGraphicsTextItem

    Quote Originally Posted by wysota View Post
    Try setting focus policy of those troublesome widgets to NoFocus.
    You mean combo boxes? I've already tried this and found that then I loose the "editable" ability for them (combo box still allows me to select its current value with a mouse but keyboard input doesn't work). It's not critical for font selection but very important for font size combo box.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Interactive text formatting in QGraphicsTextItem

    I don't know how you would expect it to work then... You either have focus in one item or the other, not in both at once... What you can do is to remember the previously focused item so that you know what to apply the formatting on.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2009
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Interactive text formatting in QGraphicsTextItem

    Quote Originally Posted by wysota View Post
    I don't know how you would expect it to work then... You either have focus in one item or the other, not in both at once...
    I have created a couple of screenshots that demonstrate the behavior I need. The first one is an MS Visio diagram and the second one is an OOo Draw diagram.

    As you can see on these shots the text cursor (caret) is in font size combo box and it is possible to edit its value with keyboard while the shape on the "scene" remains visually active, selected and seems doesn't loose focus so the text selection is not cleared and displayed using "active" colors.
    Attached Images Attached Images

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Interactive text formatting in QGraphicsTextItem

    "Visually active" means "selected". Selection and focus are two different things. Multiple things can be selected but only one can have keyboard focus.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2009
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Interactive text formatting in QGraphicsTextItem

    Quote Originally Posted by wysota View Post
    "Visually active" means "selected". Selection and focus are two different things. Multiple things can be selected but only one can have keyboard focus.
    Mmm, well, I see... Do you mean that an item can be selected and not have focus at the same time? What should I do to achieve this? How to keep an item selected when focus leaves the scene? By default QGraphicsTextItem becomes inactive when I select combo box on the toolbar. Diagramscene demo doesn't show this ability. Furthermore, in this demo the text item exits text editing mode when it looses focus thus loosing the text selection. I've tried to override focus in and focus out event handlers of the item but it didn't help. Should I reimplement some scene events (currently I only reimplement some items' and view's events and use the standard scene)? Can you point me to the working example?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Interactive text formatting in QGraphicsTextItem

    Quote Originally Posted by olelukoie View Post
    Mmm, well, I see... Do you mean that an item can be selected and not have focus at the same time? What should I do to achieve this?
    Nothing. Selection and focus are two separate mechanisms controled by two different flags.

    By default QGraphicsTextItem becomes inactive when I select combo box on the toolbar.
    Because it loses focus and was never selected. If you select it, it will stay that way until you deselect it.

    Diagramscene demo doesn't show this ability. Furthermore, in this demo the text item exits text editing mode when it looses focus thus loosing the text selection.
    Was it ever selected?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jan 2009
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Interactive text formatting in QGraphicsTextItem

    Quote Originally Posted by wysota View Post
    Was it ever selected?
    Surely yes. Run diagramscene demo, create text item, enter some text, select some portion of this text and click inside the font size combo box. Text selection would be cleared (lost). My question is how to keep it so that formatting changes apply to selected text fragment only and not to the whole text of the item.

  10. #10
    Join Date
    Jan 2009
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Interactive text formatting in QGraphicsTextItem

    So can anybody help me or point to a working example?

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Interactive text formatting in QGraphicsTextItem

    We still haven't seen a minimal compilable example reproducing the problem
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QGraphicsTextItem and text cursor position via QPoint
    By Lykurg in forum Qt Programming
    Replies: 2
    Last Post: 10th July 2017, 18:38
  2. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  3. Rich text in QGraphicsTextItem
    By maverick_pol in forum Qt Programming
    Replies: 3
    Last Post: 29th September 2008, 20:08
  4. Replies: 9
    Last Post: 22nd February 2008, 16:22
  5. xhtml/css text formatting
    By kernel_panic in forum Qt Programming
    Replies: 10
    Last Post: 30th October 2007, 14:21

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.