Results 1 to 11 of 11

Thread: Mouse DoubleClick problem

  1. #1
    Join Date
    Sep 2014
    Posts
    94
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Mouse DoubleClick problem

    hi,

    i want when mouse double click on widget it should show central to window ..

    and again double click i should go to prevoius position ...


    i tried this

    Qt Code:
    1. void Widget::mouseDoubleClickEvent(QMouseEvent *pEvent)
    2. {
    3. if(pEvent->MouseButtonDblClick )
    4. {
    5.  
    6. QRect screenGeometry = QApplication::desktop()->screenGeometry();
    7. int x = (screenGeometry.width() - this->width()) / 2;
    8. int y = (screenGeometry.height()- this->height()) / 2;
    9. this->move(x, y);
    10. }
    11. else
    12. {
    13. this->move(this->x(),this->y());
    14. pEvent->accept();
    15. }
    16.  
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 
    First condition is working but second condition is not working can anybody give solution...
    Last edited by anda_skoa; 8th August 2016 at 16:21. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Mouse DoubleClick problem

    MouseButtonDblClick is an enum value, its integer value is 176, which is always "true"

    The code in the else branch also doesn't do anything other than explicitly accepting the event.
    The move's arguments are the widget's current position.

    Cheers,
    _

  3. #3
    Join Date
    Sep 2014
    Posts
    94
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Mouse DoubleClick problem

    then how can i set to previous position

  4. #4
    Join Date
    Sep 2014
    Posts
    94
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default mouse double click event

    hi,

    i am setting my widget when mouse double click to center my system ...its working again when i double click it is not going to previous position how to set can anybody help

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Mouse DoubleClick problem

    Well, you need to store the old position before you move.

    Cheers,
    _

  6. #6
    Join Date
    Sep 2014
    Posts
    94
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Mouse DoubleClick problem

    how can is store can you give some code ...

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Mouse DoubleClick problem

    Maybe you should first have a look at one or more C++ tutorials before attempting to create a full application.

    Declaring and using member variables is something you just need to know

    E.g. http://www.cplusplus.com/doc/tutorial/classes/

    Cheers,
    _

  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Mouse DoubleClick problem

    i am setting my widget when mouse double click to center my system
    And think about what your current code is doing: You are handling a double-click event. It is always a double-click event, so it makes no sense to test to see if it is.

    So in your event handler, not only do you need to save the current window position the first time through the handler (and of course, before you move the window to the center), but you also need to save the fact that it is the first double-click event. The next time, you check your variable to see "has there already been a double click event?" and if the answer is yes, you move the window back to the coordinates you saved during the first pass. You also reset your variable to say that you are ready for a new "first pass".

    And as anda_skoa says, if you don't know how to write the code to implement that kind of logic, then you need to study some basic C++.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  9. #9
    Join Date
    Sep 2014
    Posts
    94
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Get previous position of framelesswidget

    Hi ,


    i am using frameless widget on top of mainwindow...

    how to get startup position of frameless widget when when mouse double click ...

    i am moving widget .... on top window...

    when i double click it should go to previous position...

    how to set....

  10. #10
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    506
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Get previous position of framelesswidget

    Well, store the position before you move the widget, and move() it back to stored position when you double click.

    Ginsengelf

  11. #11
    Join Date
    Sep 2014
    Posts
    94
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Mouse DoubleClick problem

    can u send some code example for that

Similar Threads

  1. Replies: 1
    Last Post: 21st October 2014, 16:59
  2. QListWidget -> DoubleClick
    By Ifoerster in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2014, 21:39
  3. DoubleClick on QwtLegend
    By hassinoss in forum Qwt
    Replies: 2
    Last Post: 11th February 2014, 17:37
  4. Ogre+qt mouse event (add object with mouse problem)
    By rimie23 in forum Qt Programming
    Replies: 7
    Last Post: 24th April 2012, 10:49
  5. [QT4 & XP] doubleClick on QtreeView
    By incapacitant in forum Newbie
    Replies: 2
    Last Post: 2nd March 2006, 12:15

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.