MyWidget
::MyWidget( QWidget* parent
){
mFixedX = 0;
mDragging = false;
}
MyWidget::~MyWidget()
{
}
{
if( e->buttons() & Qt::RightButton )
mFixedX = e->globalPos()->x();
}
{
if( !mDragging && ( e->buttons() & Qt::RightButton )
mDragging = true;
if( mDragging )
move( mFixedX, e->globalPos()->y();
}
{
mDragging = false;
}
MyWidget::MyWidget( QWidget* parent )
:QWidget( parent )
{
mFixedX = 0;
mDragging = false;
}
MyWidget::~MyWidget()
{
}
void MyWidget::mousePressEvent( QMouseEvent* e )
{
if( e->buttons() & Qt::RightButton )
mFixedX = e->globalPos()->x();
}
void MyWidget::mouseMoveEvent( QMouseEvent* e )
{
if( !mDragging && ( e->buttons() & Qt::RightButton )
mDragging = true;
if( mDragging )
move( mFixedX, e->globalPos()->y();
}
void MyWidget::mouseReleaseEvent( QMouseEvent* e )
{
mDragging = false;
}
To copy to clipboard, switch view to plain text mode
The minimal class definition should be:
{
Q_OBJECT
public:
MyWidget
( QWidget* parent
= NULL );
~MyWidget();
protected:
private:
int mFixedX;
bool mDragging;
}
class MyWidget : public QWidget
{
Q_OBJECT
public:
MyWidget( QWidget* parent = NULL );
~MyWidget();
protected:
virtual void mousePressEvent( QMouseEvent* );
virtual void mouseMoveEvent( QMouseEvent* );
virtual void mouseReleaseEvent( QMouseEvent* );
private:
int mFixedX;
bool mDragging;
}
To copy to clipboard, switch view to plain text mode
Should work fine.
Marcel.
Bookmarks