1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| #include <QtGui>
class MyWidget : public QWidget
{
public:
MyWidget(QWidget *parent = 0)
{
setSizeIncrement(2,3);
}
~MyWidget(){}
QSize sizeHint() const{return QSize(200,300);}
protected:
void paintEvent(QPaintEvent *e)
{
QPainter p(this);
p.drawLine(0,0,width(),height());
}
// Pour tester : on essaie de maintenir w <= 2h/3
void resizeEvent(QResizeEvent *e)
{
int h = e->size().height(), wd = 2*h/3;
if (e->size().width() > wd) resize(QSize(wd, h));
}
};
class MainWindow : public QMainWindow
{
public:
MainWindow(QWidget *parent = 0)
{
setSizeIncrement(2,3);
MyWidget *widget = new MyWidget(this);
setCentralWidget(widget);
}
~MainWindow(){}
protected:
// Pour tester : on essaie de maintenir w <= 2h/3
void resizeEvent(QResizeEvent *e)
{
int h = e->size().height(), wd = 2*h/3;
if (e->size().width() > wd) resize(QSize(wd, h));
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow win; win.show();
return a.exec();
} |
Partager