Results 1 to 9 of 9

Thread: Cursor stops being redrawn when QTextEdit::dropEvent() overrided

  1. #1
    Join Date
    Nov 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Question Cursor stops being redrawn when QTextEdit::dropEvent() overrided

    When I override QTextEdit::dropEvent() and do a drag and drop of text, the cursor stops blinking, stays at its last position, and is no longer redrawn. Is there a call that can be made to restore the cursor drawing?

    I've tried calling ensureCursorVisible(), setFocus(), and update() ...

    Any help appreciated.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Cursor stops being redrawn when QTextEdit::dropEvent() overrided

    Do you invoke the base class implementation? Doesn't text drag and drop work by default?

  3. #3
    Join Date
    Nov 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Cursor stops being redrawn when QTextEdit::dropEvent() overrided

    Hi Jacek,

    That's the problem: if I invoke the base class QTextEdit::dropEvent(), then the cursor is repainted properly, but I'm trying to override the base class method.

    What I'm trying to do is subclass QTextEdit to be able to have image icons within text. The image icons are to point back to some data. I do this with QTextImageFormat::setProperty(). But when the icons get selected and drag and dropped, the QTextEdit::dropEvent() wipes out that associated information.

    If it weren't for that, I'd just use the default drag-and-drop.

    As a workaround I've also tried calling QDropEvent::setDropAction(Qt::CopyAction) before calling the base class QTextEdit::dropEvent() - with the intention of copying the QTextImageFormat property over to the copy and then deleting the drag source - but the QTextEdit::dropEvent() seems to still do a move instead of a copy, deleting the source information ...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Cursor stops being redrawn when QTextEdit::dropEvent() overrided

    Have you tried the createMimeDataFromSelection() and insertFromMimeData() methods instead? QTextEdit inherits QScrollArea, so its drop event works a bit differently.

  5. #5
    Join Date
    Nov 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Cursor stops being redrawn when QTextEdit::dropEvent() overrided

    Thanks for the suggestion. I hadn't tried them yet, but from a quick test, they don't seem to retain the user property of the QTextImageFormat icons that are drag and dropped. I may have to write some mime data handling or find some other solution.

  6. #6
    Join Date
    Feb 2010
    Posts
    52
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Default Re: Cursor stops being redrawn when QTextEdit::dropEvent() overrided

    Hi.
    I know this threads a bit ancient, but was a solution found ?

    I have a similar problem. I'm overriding QTextEdit::dropEvent to handle drops of objects dragged. I need to construct the text to be inserted based on the mimedata being dragged. For example I may want to drop a file on the text edit and insert the files filename. I then simply call insertPlainText(myString) which inserts the text as expected.

    I then encounter the same problem with the cursor not being correctly drawn afterwards.

    The only workaround I've found is to call setText(myString) on the QMimeData object, (using a const_cast), and then calling the QTextEdit::dropEvent(event) to handle the insertion. This works but seems like a hack and surely isn't the right thing to do.

    Any suggestions ?
    Cheers,
    Chris.

  7. #7
    Join Date
    May 2017
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Cursor stops being redrawn when QTextEdit::dropEvent() overrided

    Hi.

    Now this is really old, but I've hit the same problem, and have found a solution:

    this->setReadOnly(true);
    QTextEdit::dropEvent(ev);
    this->setReadOnly(false);

  8. #8
    Join Date
    Sep 2021
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Cursor stops being redrawn when QTextEdit::dropEvent() overrided

    I have the same problem and I don't understand what this code does, can you explain more

  9. #9
    Join Date
    Sep 2021
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Cursor stops being redrawn when QTextEdit::dropEvent() overrided

    I solved the problem by calling the default dropEvent function and pass the current event to it
    like this:

    Qt Code:
    1. void myTextEdit::dropEvent(QDropEvent *event)
    2. {
    3. if(event->mimeData()->hasText())
    4. QTextEdit::dropEvent(event);
    5. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by d_stranz; 15th September 2021 at 18:21. Reason: missing [code] tags

  10. The following user says thank you to mohamed469 for this useful post:

    d_stranz (15th September 2021)

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.