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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
widget1 = new QWidget;
widget2 = new QWidget;
widget3 = new QWidget;
widget4 = new QWidget;
widget5 = new QWidget;
widget6 = new QWidget;
widget7 = new QWidget;
widget8 = new QWidget;
widget9 = new QWidget;
QVBoxLayout * vBoxLayout1 = new QVBoxLayout;
QHBoxLayout * hBoxLayout1 = new QHBoxLayout;
QVBoxLayout * vBoxLayout2 = new QVBoxLayout;
QHBoxLayout * hBoxLayout2 = new QHBoxLayout;
setAllBackGround(); // tous les background sont définis dans cette fonction
setAllPolicies(); // tous les setPolicy et similaires sont placé dans cette fonction
placeAllWidgets(vBoxLayout1, hBoxLayout1, vBoxLayout2, hBoxLayout2); //place les bon widget dans le bon layout
placeAllLayouts(vBoxLayout1, hBoxLayout1, vBoxLayout2, hBoxLayout2); // imbrique correctement les layouts
this->setCentralWidget(widget1);
}
MainWindow::~MainWindow()
{
}
void MainWindow::setAllBackGround()
{
widget2->setStyleSheet("background-color:#69bf3a;");
widget3->setStyleSheet("background-color:#009fff;");
widget4->setStyleSheet("background-color:#ffc484;");
widget5->setStyleSheet("background-color:#db0000;");
widget6->setStyleSheet("background-color:#f1df11;");
widget7->setStyleSheet("background-color:#e2a4ff;");
widget8->setStyleSheet("background-color:#ffffff;");
widget9->setStyleSheet("background-color:#000000;");
}
void MainWindow::setAllPolicies()
{
QSizePolicy sizePolicy_widget2(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy_widget2.setVerticalStretch(1);
widget2->setSizePolicy(sizePolicy_widget2);
QSizePolicy sizePolicy_widget3(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy_widget3.setVerticalStretch(5);
widget3->setSizePolicy(sizePolicy_widget3);
QSizePolicy sizePolicy_widget4(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy_widget4.setHorizontalStretch(2);
widget4->setSizePolicy(sizePolicy_widget4);
QSizePolicy sizePolicy_widget5(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy_widget5.setHorizontalStretch(4);
widget5->setSizePolicy(sizePolicy_widget5);
QSizePolicy sizePolicy_widget6(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy_widget6.setVerticalStretch(4);
widget6->setSizePolicy(sizePolicy_widget6);
QSizePolicy sizePolicy_widget7(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy_widget7.setVerticalStretch(1);
widget7->setSizePolicy(sizePolicy_widget7);
QSizePolicy sizePolicy_widget8(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy_widget8.setHorizontalStretch(3);
widget8->setSizePolicy(sizePolicy_widget8);
QSizePolicy sizePolicy_widget9(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy_widget9.setHorizontalStretch(1);
widget9->setSizePolicy(sizePolicy_widget9);
}
void MainWindow::placeAllWidgets(QVBoxLayout * vBoxLayout1, QHBoxLayout * hBoxLayout1, QVBoxLayout * vBoxLayout2, QHBoxLayout * hBoxLayout2)
{
vBoxLayout1->addWidget(widget2);
vBoxLayout1->addWidget(widget3);
hBoxLayout1->addWidget(widget4);
hBoxLayout1->addWidget(widget5);
vBoxLayout2->addWidget(widget6);
vBoxLayout2->addWidget(widget7);
hBoxLayout2->addWidget(widget8);
hBoxLayout2->addWidget(widget9);
}
void MainWindow::placeAllLayouts(QVBoxLayout * vBoxLayout1, QHBoxLayout * hBoxLayout1, QVBoxLayout * vBoxLayout2, QHBoxLayout * hBoxLayout2)
{
widget1->setLayout(vBoxLayout1);
widget3->setLayout(hBoxLayout1);
widget5->setLayout(vBoxLayout2);
widget6->setLayout(hBoxLayout2);
} |
Partager