Bonjour j'essai d'apprendre le C++ via les cours Qt mais j'ai un gros problème pour positionner un layout .
Je voudrais que le layout soit à une position (10,40)<=>(x,y) mais il est toujours au milieu de ma page .
Je poste mon code ci-dessous si un âme charitable peut m'aider merci d'avance.


PS: n'hésiter pas à me reprendre si mon code est brouillon.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#include "Main.h"
//#include <QMenu>
//#include <QMenuBar>
 
/*QRadioButton *radiobutton = new QRadioButton(w); */
 
 
 
Main::Main( QMainWindow* parent, Qt::WFlags fl )
   : QMainWindow( parent, fl )
{
   setWindowTitle( tr("Test              cours QT") );
   this->setMaximumSize ( 1024, 900 );
   this->setMinimumSize ( 1024, 900 );
   //creation du widget central
   centralwidget = new QWidget; // parent widget
   centralwidget->setFixedSize(1024,768);
   //creation de la barre d'outils principale
   //maintoolbar = new QToolBar;
   QToolBar* maintoolbar = new QToolBar(this);
   // Création des QFont
   QFont titre1("FreeSerif",18,75);
   QFont titre2("FreeSerif",16,75);
   QFont titre3("FreeSerif",14,75);
   QFont normal("FreeSerif",12);
   // Création des boutons
   bouton1 = new QPushButton( "Titre1");
   bouton2 = new QPushButton( "Titre2");
   bouton3 = new QPushButton( "Titre3");
   bouton4 = new QPushButton( "Normal");
   //Création des tableaux
   table1 = new QTableWidget(10,5);
   table2 = new QTableWidget(6,3);
   //Customisation des tableaux
   table1->horizontalHeader()->setFixedHeight(30);
   table1->horizontalHeader()->resizeSection(0,110);
   table1->horizontalHeader()->resizeSection(1,200);
   table1->horizontalHeader()->resizeSection(2,150);
   table1->horizontalHeader()->resizeSection(3,85);
   table1->horizontalHeader()->resizeSection(4,60);
   table1->setHorizontalHeaderLabels(QString("Numero Item1;Item2;Item3;Item4;Item5").split(";"));
   table1->verticalHeader()->hide();
   table2->horizontalHeader()->setFixedHeight(30);
   table2->horizontalHeader()->resizeSection(0,110);
   table2->horizontalHeader()->resizeSection(1,200);
   table2->horizontalHeader()->resizeSection(2,150);
   table2->setHorizontalHeaderLabels(QString("Item1;Item2;Item3").split(";"));
   table2->verticalHeader()->hide();
 
   // Customisation des boutons
   bouton1->setFixedSize(100, 40);
   bouton1->setFont(QFont(titre1));
   bouton1->setCursor(Qt::PointingHandCursor);
   bouton2->setFixedSize(100, 40);
   bouton2->setFont(QFont(titre2));
   bouton2->setCursor(Qt::PointingHandCursor);
   bouton3->setFixedSize(100, 40);
   bouton3->setFont(QFont(titre3));
   bouton3->setCursor(Qt::PointingHandCursor);
   bouton4->setFont(QFont(normal));
   bouton4->setFixedSize(100, 40);
   // Creation d'un layout horizontal
   QHBoxLayout *buttonsLayout = new QHBoxLayout(centralwidget);
   // Insertion de bouton dans le layout
   buttonsLayout->addWidget(bouton1);
   buttonsLayout->addWidget(bouton2);
   buttonsLayout->addWidget(bouton3);
   buttonsLayout->addWidget(bouton4);
 
   // Customisation du layout
   QRect pos1(10,100,420,40);
   buttonsLayout->setGeometry(pos1);
 
   // Affichage du central widget
   setCentralWidget(centralwidget );