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 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    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.


  2. #2
    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    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.


  4. #4
    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

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    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.


  6. #6
    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?

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    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.


  8. #8
    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.

  9. #9
    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?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    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.


  11. #11
    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
    We still haven't seen a minimal compilable example reproducing the problem
    "a minimal compilable example reproducing the problem" is a standard diagramscene example that comes with Qt4. I have already described the steps you can follow to see the problem with this example. See my previous reply.

    Of course if you insist I can upload my own testing project but it's not 'minimal' by any means and besides is just a testing project so it doesn't have any good readable class hierarhy nor comments neither was created from the best programming practices POV. And it have a russian only UI and is not localizable for english support . Do you wanna see it?

    PS. I wanted to add links to several bugs in Qt's bugzilla that are important for me and relate to this project and found that the UI of bugzilla is completely changed and old bug report numbers do not fit it anymore. So I give you the old numbers I have: 138596, 206294, 221584. For example one of these bugs reported that QGraphicsTextItem could not align text by center or by right border and this ability is critical for the project I planned to work on. So if these bugs are still valid (not fixed, as they were marked several days ago) than it's completely useless to continue my studying of GV framework as I won't be able to create what I need.
    Last edited by olelukoie; 27th October 2009 at 14:53.

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

    Default Re: Interactive text formatting in QGraphicsTextItem

    Quote Originally Posted by olelukoie View Post
    "a minimal compilable example reproducing the problem" is a standard diagramscene example that comes with Qt4.
    Not really. It works just fine You can see that the example works on the level of items, not its content.

    I have already described the steps you can follow to see the problem with this example.
    So be so kind and craft that compilable example reproducing the problem if you want me to devote my private time to help you.

    Of course if you insist I can upload my own testing project but it's not 'minimal'
    That won't do us (and you especially) any good. The point of a minimal compilable example is that you remove everything that might have influence on the outcome even if you don't think it should have any influence. Another point of a minimal compilable example is for you to think again about your problem. In most cases this is enough to solve a problem.

    And it have a russian only UI and is not localizable for english support
    This is not a problem for me in particular.
    Do you wanna see it?
    Not really. I want to understand why don't you just store the selection and then apply your formatting on that selection. You're still confusing focus and selection... Only ONE item can have focus at the same time. If you want it to go to the editable combobox for changing the font size, the text item WILL lose it. The bright side is YOU DON'T NEED IT.

    See QTextCursor::selectionStart() and QTextCursor::selectionEnd(). These have nothing to do with the focus. Also see QTextEdit::setExtraSelections() - if you want something similar for your item, just implement it.
    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, 19:38
  2. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49
  3. Rich text in QGraphicsTextItem
    By maverick_pol in forum Qt Programming
    Replies: 3
    Last Post: 29th September 2008, 21:08
  4. Replies: 9
    Last Post: 22nd February 2008, 17:22
  5. xhtml/css text formatting
    By kernel_panic in forum Qt Programming
    Replies: 10
    Last Post: 30th October 2007, 15: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
  •  
Qt is a trademark of The Qt Company.