Results 1 to 5 of 5

Thread: Drag problem to setStartDragTime

  1. #1
    Join Date
    Apr 2008
    Posts
    41
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Drag problem to setStartDragTime

    In my program I used QApplication::setStartDragDistance(30),QApplicatio n::setStartDragTime(1000) to changed ths drag start time and the distance,but it not work ,it also drag immediately
    the code is like this,can you help me.

    .H
    Qt Code:
    1. #ifndef QDRAPBUTTON_H
    2. #define QDRAPBUTTON_H
    3.  
    4. #include <QPushButton>
    5. #include <QApplication>
    6.  
    7. QT_BEGIN_NAMESPACE
    8. QT_END_NAMESPACE
    9.  
    10. class QDrapButton : public QPushButton
    11. {
    12. public:
    13. QDrapButton(QWidget *parent);
    14. protected:
    15. void mousePressEvent(QMouseEvent *event);
    16. void mouseMoveEvent(QMouseEvent *event) ;
    17. private:
    18. };
    19.  
    20. #endif
    To copy to clipboard, switch view to plain text mode 

    .CPP

    Qt Code:
    1. #include <QtGui>
    2.  
    3. #include "QDrapButton.h"
    4. bool m_bMove ;
    5. int m_nMoveX ;
    6. int m_nMoveY ;
    7. QDrapButton::QDrapButton(QWidget *parent)
    8. : QPushButton(parent)
    9. {
    10. QApplication::setStartDragDistance(30) ;
    11. QApplication::setStartDragTime(1000) ;
    12. m_bMove = false ;
    13. m_nMoveX = 0 ;
    14. m_nMoveY = 0 ;
    15. }
    16.  
    17. void QDrapButton::mousePressEvent(QMouseEvent *event)
    18. {
    19. QPoint hotSpot = event->pos();
    20.  
    21. QMimeData *mimeData = new QMimeData;
    22. mimeData->setText(objectName());
    23. mimeData->setData("application/x-hotspot",
    24. QByteArray::number(hotSpot.x())
    25. + " " + QByteArray::number(hotSpot.y()));
    26. mimeData->setImageData(icon()) ;
    27. QPixmap pixmap(size());
    28. render(&pixmap);
    29.  
    30. QDrag *drag = new QDrag(this);
    31. drag->setMimeData(mimeData);
    32. drag->setPixmap(pixmap);
    33. drag->setHotSpot(hotSpot);
    34.  
    35. Qt::DropAction dropAction = drag->start();
    36.  
    37. if (dropAction == Qt::MoveAction)
    38. {
    39. close();
    40. update();
    41. }
    42. return QPushButton::mousePressEvent(event) ;
    43. }
    44.  
    45. void QDrapButton::mouseMoveEvent(QMouseEvent *event)
    46. {
    47. QPoint newPoint = event->pos() ;
    48. m_nMoveX = 0 ;
    49. m_nMoveY = 0 ;
    50. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 12th September 2008 at 17:28. Reason: missing [code] tags

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drag problem to setStartDragTime

    First, you are overriding mousePressEvent, and starting the draf urself.
    How can you expect the QApplication setting to work ?

    You need to check those values when starting the drag urself

  3. #3
    Join Date
    Apr 2008
    Posts
    41
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drag problem to setStartDragTime

    Thank you
    but if I do not overriding the QPushButton's mousePressEvent,how can I make the QPushButton can drag when mouse press.And how can I make the QApplication::setStartDragTime work.

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drag problem to setStartDragTime

    You can make a check yourself like -
    Qt Code:
    1. if ((startPos - currentPos).manhattanLength() >=QApplication::startDragDistance()
    2. && elapsedTime > qApp->startDragTime() )
    3. {
    4. startTheDrag();
    5. }
    To copy to clipboard, switch view to plain text mode 

    I hope u get the idea

  5. #5
    Join Date
    Apr 2008
    Posts
    41
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drag problem to setStartDragTime

    Thank you ,I know the problem now ;

Similar Threads

  1. Problem with Drag Drop for QWT Graph
    By Ankitha Varsha in forum Qwt
    Replies: 2
    Last Post: 23rd January 2008, 05:21
  2. Problem wirh Drag and Drop for QWT Graph
    By Ankitha Varsha in forum Qwt
    Replies: 1
    Last Post: 22nd January 2008, 12:23
  3. Problem with a cursor during Drag and Drop
    By mtrpoland in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2007, 15:46
  4. Drag n Drop problem
    By ScoOteR in forum Qt Programming
    Replies: 1
    Last Post: 21st March 2007, 10:52
  5. Drag 'n Drop problem
    By kiker99 in forum Qt Programming
    Replies: 4
    Last Post: 16th January 2006, 16:35

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.