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
Code:
#ifndef QDRAPBUTTON_H
#define QDRAPBUTTON_H
#include <QPushButton>
#include <QApplication>
QT_BEGIN_NAMESPACE
QT_END_NAMESPACE
{
public:
protected:
private:
};
#endif
.CPP
Code:
#include <QtGui>
#include "QDrapButton.h"
bool m_bMove ;
int m_nMoveX ;
int m_nMoveY ;
QDrapButton
::QDrapButton(QWidget *parent
){
m_bMove = false ;
m_nMoveX = 0 ;
m_nMoveY = 0 ;
}
{
QPoint hotSpot
= event
->pos
();
mimeData->setText(objectName());
mimeData->setData("application/x-hotspot",
mimeData->setImageData(icon()) ;
render(&pixmap);
drag->setMimeData(mimeData);
drag->setPixmap(pixmap);
drag->setHotSpot(hotSpot);
Qt::DropAction dropAction = drag->start();
if (dropAction == Qt::MoveAction)
{
close();
update();
}
}
{
QPoint newPoint
= event
->pos
() ;
m_nMoveX = 0 ;
m_nMoveY = 0 ;
}
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
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.
Re: Drag problem to setStartDragTime
You can make a check yourself like -
Code:
if ((startPos
- currentPos
).
manhattanLength() >
=QApplication::startDragDistance() && elapsedTime > qApp->startDragTime() )
{
startTheDrag();
}
I hope u get the idea :)
Re: Drag problem to setStartDragTime
Thank you ,I know the problem now ;