About drag and drop



  • Hi
    I'm japanese high school student and not so good at English, so I'm sorry if you have some trouble in reading…(´・ω・`)

    I want to drag text from qlineedit and drop qtextbrowser and show it but I have some puestions.
    I think there're two ways to do that first.

    1.reimplement dragEnterEvent in MainWindow class and only if "textBrowser->geometry.contains(event->pos())" is true,accept the event.

    2.create new class that inherits qtextbrowser and reimplement dragEnterEvent and accept the event.

    The first way works well but in the second way,I couldn't drop the text on the textbrowser without its border.
    why is this occur?
    and is there any good way to let it work?

    or is the first way ordinary in qt?



  • Hi, general info may be found in the relevant documentation documents, real-life use case in the examples.


  • Qt Champions 2017

    Hi and welcome

    Both methods are valid and should both work.

    ,I couldn't drop the text on the textbrowser without its border.

    Im not sure what the "without its border." means ?



  • Oh,thanks!
    I've read them before, but now I see one of the examples and add "mouseMoveEvent" to my program, it worked!



  • @mrjj
    thanks for answering but now solved!
    it means "textbrowser's frame"



  • Repletion:
    it turns out that the bad point of my program is using "acceptProposedAction" instead of "accept".



  • @rick_nakano
    Sorry , this have nothing to do with that...
    I rewrite my program as below and then it worked well.

    void TextBrowser::dragMoveEvent(QDragMoveEvent* event)
    {
    event->acceptProposedAction();
    }


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.