[Qt-interest] resizeEvent get's only called _after_ resize
Christoph Fritz
chris_honschu at gmx.de
Sun Jul 19 12:23:07 CEST 2009
On Sunday, 19. July 2009, Sean Harmer wrote:
> > What I need is a function that gives me access to the
> > resize-process itself. So that the window can always stay in
> > 4:3 ratio and won't be snapped back after the resize event.
>
> Try reimplementing the int QWidget::heightForWidth ( int w )
> const function in your window class to return a height
> appropriate to the passed width according to your desired
> aspect ratio.
Presentation of "Understanding Qt's Layouts", on sheet 40 says:
- Must reimplement heightForWidth(int) and set the
height-for-width flag of QSizePolicy
- Can be used to keep constant aspect ratios
- Caveat: On X11, if the entire window has height-for-width, the
window has no minimum size.
http://chaos.troll.no/~ahanssen/devdays2007/DevDays2007-Layouts.pdf
I tried so, but it didn't work. Any guess?
In the constructor I did:
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->sizePolicy().setHeightForWidth(true);
}
declared the reimplementation of heightForWidth:
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
virtual int heightForWidth ( int w ) const;
and wrote a 1:1 ratio test:
int MainWindow::heightForWidth ( int w ) const {
return w;
}
More information about the Qt-interest-old
mailing list