tags:

views:

62

answers:

1

Just as the title said, when I resize the window, if I make it widen , I want the window's height resize proportional to make the window has the same ratio. I just do the logic in paintEvent, but it doesn't work fine, can some guys have any solution?

I don't think do resizing in resizeEvent is a great way, the best result is that window flickering, but I want the fluent way

+1  A: 

Don't do it in paintEvent but instead void QWidget::resizeEvent ( QResizeEvent * event ). Then you can compare event->size() and event->oldsize() to see which dimension got changed, then resize to match the other dimension to the changed one.

EDIT: Note that when you resize the window inside the resizeEvent function, you will create another resize event. So make sure you only resize if there's been a change that brought the window to a wrong aspect ratio, otherwise you will create infinite recursion to the function and a stack overflow.

teukkam
I just did this in resizeEvent. And I think may some of code has bugs.And base on your answer, I think mine thought was applicable, thx!I will try again
Martin Luo