Results 1 to 6 of 6

Thread: Block Widget Movement

  1. #1
    Join Date
    Jan 2007
    Posts
    20
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Block Widget Movement

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Block Widget Movement

    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

  3. #3
    Join Date
    Jan 2007
    Posts
    20
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Block Widget Movement

    Quote Originally Posted by marcel View Post
    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

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Block Widget Movement

    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.

  5. The following user says thank you to marcel for this useful post:

    shyam prasad (3rd April 2007)

  6. #5
    Join Date
    Jan 2007
    Posts
    20
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Block Widget Movement

    [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 .

  7. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Block Widget Movement

    Qt Code:
    1. MyWidget::MyWidget( QWidget* parent )
    2. :QWidget( parent )
    3. {
    4. mFixedX = 0;
    5. mDragging = false;
    6. }
    7.  
    8. MyWidget::~MyWidget()
    9. {
    10. }
    11.  
    12. void MyWidget::mousePressEvent( QMouseEvent* e )
    13. {
    14. if( e->buttons() & Qt::RightButton )
    15. mFixedX = e->globalPos()->x();
    16. }
    17.  
    18. void MyWidget::mouseMoveEvent( QMouseEvent* e )
    19. {
    20. if( !mDragging && ( e->buttons() & Qt::RightButton )
    21. mDragging = true;
    22. if( mDragging )
    23. move( mFixedX, e->globalPos()->y();
    24. }
    25.  
    26. void MyWidget::mouseReleaseEvent( QMouseEvent* e )
    27. {
    28. mDragging = false;
    29. }
    To copy to clipboard, switch view to plain text mode 


    The minimal class definition should be:
    Qt Code:
    1. class MyWidget : public QWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. MyWidget( QWidget* parent = NULL );
    6. ~MyWidget();
    7.  
    8. protected:
    9. virtual void mousePressEvent( QMouseEvent* );
    10. virtual void mouseMoveEvent( QMouseEvent* );
    11. virtual void mouseReleaseEvent( QMouseEvent* );
    12.  
    13. private:
    14. int mFixedX;
    15. bool mDragging;
    16. }
    To copy to clipboard, switch view to plain text mode 

    Should work fine.

    Marcel.

Similar Threads

  1. Controlling which widget on top layer?
    By JonathanForQT4 in forum Qt Programming
    Replies: 6
    Last Post: 22nd March 2007, 15:27
  2. Replies: 4
    Last Post: 10th March 2007, 19:01
  3. Pin/Unpin Dock Widget
    By charlesD in forum Newbie
    Replies: 1
    Last Post: 21st June 2006, 07:57
  4. Replies: 4
    Last Post: 24th March 2006, 23:50
  5. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 15:16

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.