PDA

View Full Version : Block Widget Movement



shyam prasad
3rd April 2007, 08:16
Hi ..

1 ) I want block the move ment of the widget horizentolly , after clicking mouse left button .

i.e: the entire widget should not be movable horizontally , after pressing the mouse left button in the widget .


2 )

when i press the mouse right button the entire widget should be in black color , including the caption bar .



Thanks

marcel
3rd April 2007, 08:36
You're gonna have to be more detailed than that!

What kind of widget is that ( you mentioned that it has a caption bar ).
What is the parent widget? What kind of layout does the parent widget has?

Marcel

shyam prasad
3rd April 2007, 09:01
You're gonna have to be more detailed than that!

What kind of widget is that ( you mentioned that it has a caption bar ).
What is the parent widget? What kind of layout does the parent widget has?

Marcel


Thanks Marcel ,

Here my widget does not have parent widget .
it should not be movable horizentolly after clicking right mouse button .


Marcel , i am waiting for u r reply

Thanks

marcel
3rd April 2007, 09:31
Does it move programatically, as a response to some other event or you drag it with the mouse?

Either way, you should fix its x position to the one it had when you pressed the right button.

If you move it with the mouse, then reimplement mousePressEvent, and in it store the it's x position if the right button is clicked.

Also you must have reimplemented mouseMoveEvent. Here you just have to move your widget only on the vertical by keeping the stored x from mousePressEvent.

Still need more details if you want a more particular solution.

shyam prasad
3rd April 2007, 17:13
[QUOTE=marcel;33411]Does it move programatically, as a response to some other event or you drag it with the mouse?


Thanks Marcel .

Widget should be move through the mouse .

Can u show me a piece of code .

Thanks .

marcel
3rd April 2007, 19:27
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;
}



The minimal class definition should be:


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;
}


Should work fine.

Marcel.