Form in 4 gleiche Layouts teilen

Alles rund um die Programmierung mit Qt
Antworten
bierber
Beiträge: 72
Registriert: 27. November 2006 14:12

Form in 4 gleiche Layouts teilen

Beitrag von bierber »

Hallo,

suche eine Möglichkeit meine Form in 4 gleichgroße teile zu splitten.

Die Idee war bisher das mit dem QVBoxLayout und dem QHBoxLayout zu machen,
allerdings ist die Aufteilung nicht wie erwartet.


Erwartet:

Code: Alles auswählen

----------------------
|    1     |    2     |
----------------------
|    3     |    4     |
----------------------

Real:

Code: Alles auswählen


-3/4---------------
|         | -------|
-     1        2  
|         |         |
--------------------
(Also Layout 3 und 4 kleben in der linken oberen Ecke, Layout 2 ist nicht oben angefügt, sondern beginnt in der Mitte der Form)

Code: Alles auswählen

QHBoxLayout *lLayout_H1 =new QHBoxLayout(this);
	QHBoxLayout *lLayout_H2 =new QHBoxLayout(this);

	lLayout_H1->setGeometry(transformRect(QRect(5, 5, (this->height()/2)-6, this->width()-6)));
	lLayout_H2->setGeometry(transformRect(QRect(5, (this->height()/2), (this->height()/2)-6, this->width()-6)));

	QVBoxLayout *lLayout_1= new QVBoxLayout();
	QVBoxLayout *lLayout_2= new QVBoxLayout();
	QVBoxLayout *lLayout_3= new QVBoxLayout();
	QVBoxLayout *lLayout_4= new QVBoxLayout();

	

	lLayout_1->setGeometry(transformRect(QRect(5, 5, (this->height()/2)-6, this->width()/2-6)));
	lLayout_2->setGeometry(transformRect(QRect((this->width()/2), 5, (this->height()/2)-6, this->width()-6)));

	lLayout_3->setGeometry(transformRect(QRect(5, 5, (this->height()/2)-6, (this->width()/2)-6)));
	lLayout_4->setGeometry(transformRect(QRect((this->width()/2), (this->height()/2), (this->height()/2)-6, this->width()-6)));

	lLayout_H1->addLayout(lLayout_1);
	lLayout_H1->addLayout(lLayout_2);

	lLayout_H2->addLayout(lLayout_3);
	lLayout_H2->addLayout(lLayout_4);

	lbX1_Axis=new SlGfwLabel(this);
	lbZ1_Axis=new SlGfwLabel(this);
	lbB1_Axis=new SlGfwLabel(this);
	lbC10_Axis=new SlGfwLabel(this);
	lbW10_Axis=new SlGfwLabel(this);
	lbZ20_Axis=new SlGfwLabel(this);

	lbC20_Axis=new SlGfwLabel(this);

	lbX1_Axis->setText("X-Achse: ");
	lbC20_Axis->setText("C20-Achse: ");
	lbZ1_Axis->setText("Z1-Achse: ");
	lbB1_Axis->setText("B1-Achse: ");
	lbC10_Axis->setText("Z1-Achse: ");


	lLayout_1->addWidget(lbX1_Axis,0,0);
	lLayout_2->addWidget(lbZ1_Axis,0,0);
	lLayout_3->addWidget(lbB1_Axis,0,0);
	lLayout_4->addWidget(lbC10_Axis,0,0);
	lLayout_1->addWidget(lbW10_Axis,0,0);
	lLayout_1->addWidget(lbZ20_Axis,0,0);
	lLayout_1->addWidget(lbC20_Axis,0,0);

Sieht hier jemand warum das passiert? Ich stehe auf dem Schlauch.

Gruß

und Danke

Felix
odt
Beiträge: 128
Registriert: 12. August 2010 11:49
Kontaktdaten:

Re: Form in 4 gleiche Layouts teilen

Beitrag von odt »

zwei Top-Level-Layouts sind nicht möglich, also zwei new Layout( this ); vermeiden
explizite layout.setGeometry verhindern die automatische Layout-Anpassung bei Aenderung der Fenstergrösse, ich nehme an, dass Du dies aufgrund dem oberigen "Bug" machtest.

Code: Alles auswählen

	QHBoxLayout* root = new QHBoxLayout( this );
	QVBoxLayout* spalte1 = new QVBoxLayout();
	root->addLayout( spalte1, 1 );
	QVBoxLayout* spalte2 = new QVBoxLayout();
	root->addLayout( spalte2, 1 );
	spalte1->addWidget( new QLabel( "1" ) );
	spalte1->addWidget( new QLabel( "2" ) );
	spalte2->addWidget( new QLabel( "3" ) );
	spalte2->addWidget( new QLabel( "4" ) );
oder

Code: Alles auswählen

	QGridLayout* layout = new QGridLayout( this );
	layout->addWidget( new QLabel( "1" ), 1, 1 );
	layout->addWidget( new QLabel( "2" ), 1, 2 );
	layout->addWidget( new QLabel( "3" ), 2, 1 );
	layout->addWidget( new QLabel( "4" ), 2, 2 );
ODT Informatik GmbH, Reto Tschofenig
bierber
Beiträge: 72
Registriert: 27. November 2006 14:12

Re: Form in 4 gleiche Layouts teilen

Beitrag von bierber »

Danke, so hats dann geklappt!
Antworten