Results 1 to 6 of 6

Thread: dragging

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Arrow dragging

    Hi,
    I'm trying drag (and drop) of a text insert in a qlabel. But I see that drag event isn't called. Why? (maybe beacause on mywidget starts mouseMoveEvent also?)
    Thanks
    Qt Code:
    1. MyWidget::MyWidget( QWidget *parent, const char *name, const QGLWidget* shareWidget)
    2. : QGLWidget ( parent, name, shareWidget) {
    3.  
    4. this->setAcceptDrops(true);
    5. label = new QLabel("prove", this);
    6. }
    7.  
    8. void MyWidget::startDrag() {
    9. printf("start drag\n");
    10. QDragObject *d = new QTextDrag (this->label->text(), this);
    11. d->dragCopy();
    12. //do NOT delete d
    13. }
    14.  
    15. void MyWidget::dragEnterEvent(QDragEnterEvent* event) {
    16. printf("start drag enter event\n");
    17. event->accept(QTextDrag::canDecode(event) || QImageDrag::canDecode(event));
    18. }
    19.  
    20. void MyWidget::dropEvent(QDropEvent* event) {
    21. printf("start drop event\n");
    22. QImage image;
    23. QString text;
    24.  
    25. if (QImageDrag::decode(event, image)) {
    26. //insertImageAt(image, event->pos());
    27. }
    28. else if (QTextDrag::decode(event, text)) {
    29. //insertTextAt(text, event->pos());
    30. }
    31. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by mickey; 10th March 2006 at 15:24.
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    England
    Posts
    18
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dragging

    If I understand, you are trying to drag/drop onto a QLabel? QLabel does not handle drag/drop events.

    QLabel is derived from QFrame which is derived from QWidget. QWidget handles the drag/drop events, but the functions are protected, so they are not visible in QLabel.

    If you want drag/drop, don't use the QLabel - just override the paint function of mywidget to output the text.

    HTH

    McToo
    It's always a long day, you can't fit 86400 into a short!

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: dragging

    Sorry, I'm trying to dragging the text inside a QLabel onto "still undefined".
    To do this I put a QLabel with text onto myWidget (GL) and I code this:
    Qt Code:
    1. void MyWidget::startDrag() {
    2. printf("start drag\n");
    3. QDragObject *d = new QTextDrag (this->label->text(), this);
    4. d->dragCopy();
    5. //do NOT delete d
    6. }
    To copy to clipboard, switch view to plain text mode 
    but doesn't start. What can I insert onto myWidget to see only drag effect?
    Thanks
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    England
    Posts
    18
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dragging

    Make mywidget paint the text, not QLabel.

    You'd have to get rid of the label=new QLabel in the mywidget constructor.

    Override
    Qt Code:
    1. QWidget::paint
    To copy to clipboard, switch view to plain text mode 
    in mywidget to output whatever text you wanted.

    Then you would see the startDrag function called.

    HTH

    McToo
    It's always a long day, you can't fit 86400 into a short!

  5. #5
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: dragging

    I don't understand. I must to do drawText("some text")? my paintGL() draw openGL object.....Does it to be a GL text? I have also write on mywidget with renderText("some").....But I can't drag it; don't drag!
    Regards

  6. #6
    Join Date
    Jan 2006
    Location
    England
    Posts
    18
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dragging

    Sorry, just realised mywidget is derived from QGLWidget, so you have the same problem with mywidget as with QLabel, i.e. you don't have access to the protected drag/drop member functions from QWidget. Forget my last post, it was drivel

    Try creating a seperate QWidget derived class that will have the same screen placement and geometry as mywidget, but sits above it in the z order (use raise() stackUnder()) and is transparent setWindowOpacity() (Win & Mac only) - don't know how to make windows transparent in X. This then acts as a drag/drop target for mywidget.

    There's probably a neater way...

    McToo
    It's always a long day, you can't fit 86400 into a short!

Similar Threads

  1. Hover on mouse over while dragging
    By mooreaa in forum Qt Programming
    Replies: 3
    Last Post: 6th February 2010, 11:31
  2. QMainWindow Dragging is suspending QTimer
    By zaferaltug in forum Qt Programming
    Replies: 3
    Last Post: 10th February 2009, 14:23
  3. Dragging to windows (pyqt)
    By amicitas in forum Newbie
    Replies: 1
    Last Post: 28th September 2008, 01:09
  4. Dragging mouse selection in QTableWidget
    By yartov in forum Qt Programming
    Replies: 1
    Last Post: 12th April 2008, 16:03
  5. dragging
    By mickey in forum Newbie
    Replies: 1
    Last Post: 25th July 2006, 15:05

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.