I want qt window to resize proportional
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开发者_如何学Python window flickering, but I want the fluent way
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.
精彩评论