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.
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...
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.
Quote:
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.
Code:
{
[INDENT]qreal ratio = event->size().width()/event->size().height();
if (ratio != heightForWidth(1))
{
event->ignore();
newSize.setWidth(width());
newSize.setHeight(heightForWidth(newSize.width()));
resize(newSize.toSize());
return;
}
QDialog::resizeEvent(event
);
[/INDENT
] }
the command heightForWidth(int width) returns w/=1.6;
How can I do ?
Thanks you.
P.S. should I forget the phi number ?
Re: The event fired by the mouse click on the frame
Quote:
Originally Posted by
Placido Currò
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.
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 ?
Re: The event fired by the mouse click on the frame
Quote:
Originally Posted by
Placido Currò
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.
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.
Re: The event fired by the mouse click on the frame
Hi,
just to complete !
if we reimplement the method
Code:
bool QWidget::winEvent ( MSG
* message,
long * result
)
, 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.
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! :D