Results 1 to 9 of 9

Thread: The event fired by the mouse click on the frame

  1. #1
    Join Date
    Sep 2006
    Posts
    23
    Thanks
    8
    Qt products
    Qt3 Qt4

    Default The event fired by the mouse click on the frame

    Hi everybody,

    I would like to recalculate the correct size of my QDialog based on a specified ratio. I know, I could reimplement the resize event and force a new resize when the size of the Qdialog doesn't respect my ratio. But I thought, when the user resizes the dialog 'dragging' the frame of my dialog, I could check the new dimension of the dragged side and fix the other side. But I would to avoid that 'flickering' that happens during the recalculation of the proper size.

    So, I tried to reimplement the event wich happens when the user moves the mouse to the frame of the dialog and then clicks. But which event ?

    I set up a little sample to check which the event is, but when I click on the frame of the dialog, nothing happens. The mouse cursor, as expected, changes when it goes over the border, but no event happens, even after the mouse click. I see only the resize, after all.

    Has anybody seen 'my' event ?

    Thanks you.

    Placido.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: The event fired by the mouse click on the frame

    How about using heightForWidth to force the ratio? I don't know if it works for top-level widgets (if you set a size constraint on the window, there is a chance it will), but you might try...

  3. #3
    Join Date
    Sep 2006
    Posts
    23
    Thanks
    8
    Qt products
    Qt3 Qt4

    Default Re: The event fired by the mouse click on the frame

    Thanks for your answer.

    The heightForwidth provides useful information if you set a QLayout into the QDialog, according to the manual.

    int QWidget::heightForWidth ( int w ) const [virtual]

    Returns the preferred height for this widget, given the width w.
    If this widget has a layout, the default implementation returns the layout's preferred height. if there is no layout, the default implementation returns -1 indicating that the preferred height does not depend on the width.
    But it's not my case, I can't add a layout to my QDialog.

    If I recalculate the size of the QDialog inside of the resizeEvent, I get a stack overflow errore as I open a loop.

    Qt Code:
    1. void myClass::resizeEvent(QResizeEvent * event)
    2. {
    3.  
    4. [INDENT]qreal ratio = event->size().width()/event->size().height();
    5.  
    6. QSizeF newSize;
    7.  
    8.  
    9. if (ratio != heightForWidth(1))
    10. {
    11.  
    12. event->ignore();
    13.  
    14. newSize.setWidth(width());
    15.  
    16. newSize.setHeight(heightForWidth(newSize.width()));
    17.  
    18.  
    19.  
    20. resize(newSize.toSize());
    21.  
    22. return;
    23. }
    24.  
    25.  
    26.  
    27. QDialog::resizeEvent(event);[/INDENT]
    28. }
    To copy to clipboard, switch view to plain text mode 

    the command heightForWidth(int width) returns w/=1.6;

    How can I do ?

    Thanks you.

    P.S. should I forget the phi number ?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: The event fired by the mouse click on the frame

    Quote Originally Posted by Placido Currò View Post
    The heightForwidth provides useful information if you set a QLayout into the QDialog, according to the manual.
    No, it doesn't say that. It says that the default implementation returns -1 or what the layout tells it. It doesn't say anything about customising it. You should reimplement the method (as you see it's virtual). Maybe it'll just work... it probably won't but you won't know until you try.

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

    Placido Currò (22nd February 2007)

  6. #5
    Join Date
    Sep 2006
    Posts
    23
    Thanks
    8
    Qt products
    Qt3 Qt4

    Default Re: The event fired by the mouse click on the frame

    I would like to prevent my qdialog to resize with uncorrect size. When I check the size, my dialog has been resized (in QResizeEvent, for example), and then I have to invoke another resize. In the end, I trigger a loop because the dimension of the QDialog is integer and not qreal or float...so the ratio is rarely respected.

    How can I do ?

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: The event fired by the mouse click on the frame

    Quote Originally Posted by Placido Currò View Post
    I trigger a loop because the dimension of the QDialog is integer and not qreal or float...so the ratio is rarely respected.
    Then don't force the exact ratio. Allow differences up to 2-3 points.

  8. #7
    Join Date
    Sep 2006
    Posts
    23
    Thanks
    8
    Qt products
    Qt3 Qt4

    Default Re: The event fired by the mouse click on the frame

    Yes...but but can we prevent prevent our QDialog from uncorrect resizing ?

    Can we recalculate the correct resizing during the dragging of the frame of the QDialog ?

    As far as I know, no event happens during the dragging of the frame of the QDialog.


    Thanks you.

  9. #8
    Join Date
    Sep 2006
    Posts
    23
    Thanks
    8
    Qt products
    Qt3 Qt4

    Default Re: The event fired by the mouse click on the frame

    Hi,

    just to complete !

    if we reimplement the method
    Qt Code:
    1. bool QWidget::winEvent ( MSG * message, long * result )
    To copy to clipboard, switch view to plain text mode 
    , we can handle the native Window events before they become QT- events.

    After include "windows.h", you get the struct MSG wich gives you the information of the event. The event I want to handle is the 'on sizing' and the message is WM_SIZING.

    This way I can modify the dimensions of the QDialog and correct the ratio before it goes to the resizeEvent.

    I know that it's not a porting solution...but I couldn't see any way to correct the dimension without invoking many times the resize event.

    Thanks you.
    Placido.

  10. #9
    Join Date
    Aug 2006
    Posts
    44
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: The event fired by the mouse click on the frame

    A few more nuggets of possible interest...

    In Windows, there are several events that may help you. As Placido ponted out, there's WM_SIZING, as well as WM_ENTERSIZEMOVE and WM_EXITSIZEMOVE. There's also the ultra-powerful WM_WINDOWPOSCHANGING ( you can do a lot with that one.. but it can be dangerous ). To know specifically when parts like the title bar or frames are clicked, there are the 'non-client' events (WM_NCLBUTTONDOWN, etc.). I haven't found equivalents for these on Mac / X Windows, in case those are relevant for your task. If you do find them, dish!

Similar Threads

  1. Replies: 1
    Last Post: 9th February 2007, 09:41
  2. Mouse Over event on button
    By vishal.chauhan in forum Qt Programming
    Replies: 9
    Last Post: 10th January 2007, 05:03
  3. mouse click in QGprahicsScene
    By Morea in forum Qt Programming
    Replies: 11
    Last Post: 21st December 2006, 08:21
  4. mouse click event
    By vijay anandh in forum Qt Programming
    Replies: 1
    Last Post: 1st May 2006, 09:24
  5. QStackerWidget and mouse events
    By high_flyer in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2006, 19:25

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.