Try adding the following line at the end of your drop event:
Qt Code:
setTextCursor(insertionCursor);To copy to clipboard, switch view to plain text mode
Try adding the following line at the end of your drop event:
Qt Code:
setTextCursor(insertionCursor);To copy to clipboard, switch view to plain text mode
What happens then is that the active cursor gets to where the dropped text went (which is what I want), BUT if I click with the mouse on the text document the cursor symbol stays where it was while the invisible cursor (the active one) moves to where the mouse click went.
- is this fuzzy or am I explaining it OK?
What I want is of course them to be one and the same - but preferably w/out having to re-implement ALL mouseEvents
I think J-P already stated in some other thread that he didn't understand it and I have to agree with him - I don't understand either...
Which cursor does QTextEdit::textCursor() return?
Yeah. I know it's a little confusing - I think I read that thread too - as far as I could see other people had the same problem but I didn't find a solution for it.
QTextEdit::textCursor() returns a copy of the actual cursor. So any changes to that cursor will NOT affect the 'active' cursor.
I've attached a main.cpp file and my TextEdit I don't know if you have time to check it but if so the following steps would explain the problem
1) write some text - whatever to play with
2) select part of the text with the mouse - and do a drag-n-drop of that text to another section of the document
3) You will see that (correctly) the cursor moved to the place where the text was dropped.
4) Click on another location on the document - you willsee that the curser symbol didn't move to the place where you clicked.
5) Try pressing some keys on the keyboard - the letters will appear where you latest clicked with the mouse and NOT where the visible cursor symbol is.
I noticed that I had made some minor changes to TextEdit in the zip file - compared to example above - it was for testing and doesn't affect the behaviour
Last edited by KjellKod; 18th February 2007 at 08:44.
Ok, the example speaks for itself. Here's a workaround:
Qt Code:
{ event->mouseButtons(), Qt::ShiftModifier, event->type()); // <-- Qt::ShiftModifier is important }To copy to clipboard, switch view to plain text mode
Last edited by jacek; 18th February 2007 at 12:04. Reason: wrapped too long line
J-P Nurmi
KjellKod (18th February 2007)
That was a great workaround J-P ...
Simply by making a new dropEvent and calling the parent. I WILL use that one!![]()
(Now why didn't I think of that)
But I am still confused how the QTextCursor got all messed up - do you know?
Now when I see the Trolls code I realize that I've tried to do exactly what they're doing. I belive that it is a bug in the Qt code since setting the cursor with doesn't work.
Why is Qt::ShiftModifier important? Wouldn't it be better to use the actual modifiers for the event? I.e.
Qt Code:
event->keyboardModifiers() // instead of Qt::ShiftModifierTo copy to clipboard, switch view to plain text mode
Last edited by jacek; 18th February 2007 at 12:04. Reason: wrapped too long line
It's important because the inner QTextControl ends up using QDropEvent::proposedAction(). The proposed action is determined by a private Qt class called QDragManager according to the modifiers (QDragManager::defaultAction() in src/gui/kernel/qdnd.cpp). I found all this out by simply debugging through the dropEvent() code.
J-P Nurmi
KjellKod (18th February 2007)
I see what you mean - the shift modifier makes it into cut-n-paste rather than copy-n-paste
I've been a bit hesitant to look at Qt's code but I see now that when encountering problems like this that's definitely worthwhile![]()
Thanks again J-P.![]()
Yep, exactly.
Please don't hesitate to do so, it's definitely the most powerful way to find out why something works like it does.I've been a bit hesitant to look at Qt's code but I see now that when encountering problems like this that's definitely worthwhile![]()
The sources throughout Qt are pretty clean and understandable. However, one confusing thing when looking into the sources of Qt for the first time might be the usage of Pimpl. Whether it's a new concept or not, one gets quickly used to the way it's used in Qt.
No problem at all, happy hacking with Qt!Thanks again J-P.![]()
J-P Nurmi
Bookmarks