PDA

View Full Version : The event fired by the mouse click on the frame



Placido Currò
21st February 2007, 11:47
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.

wysota
21st February 2007, 11:54
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...

Placido Currò
21st February 2007, 13:45
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.


void myClass::resizeEvent(QResizeEvent * event)
{


qreal ratio = event->size().width()/event->size().height();

QSizeF newSize;


if (ratio != heightForWidth(1))
{

event->ignore();

newSize.setWidth(width());

newSize.setHeight(heightForWidth(newSize.width())) ;



resize(newSize.toSize());

return;
}



QDialog::resizeEvent(event);
}

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

How can I do ?

Thanks you.

P.S. should I forget the phi number ?

wysota
21st February 2007, 14:04
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.

Placido Currò
22nd February 2007, 11:08
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 ?

wysota
22nd February 2007, 11:21
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.

Placido Currò
22nd February 2007, 11:31
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.

Placido Currò
26th February 2007, 15:44
Hi,

just to complete !

if we reimplement the method
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.

Eldritch
3rd March 2007, 09:05
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