Try setting focus policy of those troublesome widgets to NoFocus.
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.
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.
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.
"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?
Nothing. Selection and focus are two separate mechanisms controled by two different flags.
Because it loses focus and was never selected. If you select it, it will stay that way until you deselect it.By default QGraphicsTextItem becomes inactive when I select combo box on the toolbar.
Was it ever selected?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.
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.
So can anybody help me or point to a working example?
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.
Not really. It works just fineYou can see that the example works on the level of items, not its content.
So be so kind and craft that compilable example reproducing the problem if you want me to devote my private time to help you.I have already described the steps you can follow to see the problem with this example.
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.Of course if you insist I can upload my own testing project but it's not 'minimal'
This is not a problem for me in particular.And it have a russian only UI and is not localizable for english support![]()
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.Do you wanna see 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.
Bookmarks