First look at the target effect
Code:
#include "mainwindow.h" #include <QApplication> #include <QTextEdit> #include <QSplitter> #include <qtextcodec>int Main (int argc, char *argv[]) {qapplication A (argc, argv); Qfont font ("ZYSong18030", 12); A.setfont (font); Set font type//main split window//second setting 0 means main window, no parent window qsplitter *splittermain = new Qsplitter (qt::horizontal, 0); Split the main window horizontally, this bar main window is divided into two parallel windows//automatically in order from left to right to modify qtextedit *textleft = new Qtextedit (QOBJECT::TR ("the"), Splittermain) ; A new Qtexteidt object is filled into the splittermain inside the textleft->setalignment (qt::aligncenter); Text Center placed, the left side of the setup finished//Right part of the split window//1, new Create a split add to the main window qsplitter *splitterright = new Qsplitter (qt::vertical, Splittermain); Vertical split Splitterright->setopaqueresize (false); Qtextedit *textup = new Qtextedit (Qobject::tr ("Top Widget"), splitterright); Textup->setalignment (Qt::aligncenter); Qtextedit *textbottom = new Qtextedit (Qobject::tr ("Bottom Widget"), splitterright); Textbottom->setalignment (Qt::aligncenter); Splittermain->setsTretchfactor (0, 0); Splittermain->setwindowtitle (Qobject::tr ("Splitter")); Splittermain->show (); This is according to the order of the program in the direction of braking set to the first row or//MainWindow w;//w.show (); return a.exec ();}
We could make a little change to make him this kind of thing, and we'd better understand qsplitter.
Code:
#include "mainwindow.h" #include <QApplication> #include <QTextEdit> #include <QSplitter> #include <qtextcodec>int Main (int argc, char *argv[]) {qapplication A (argc, argv); Qfont font ("ZYSong18030", 12); A.setfont (font); Set font type//main split window//second setting 0 means main window, no parent window qsplitter *splittermain = new Qsplitter (qt::horizontal, 0); Split the main window horizontally, this bar main window is divided into parallel two windows Qsplitter *splitterright2 = new Qsplitter (qt::vertical, Splittermain); Vertical split Splitterright2->setopaqueresize (true); Qtextedit *textleft0 = new Qtextedit (Qobject::tr ("left Widget"), splitterRight2); A new Qtexteidt object is filled into the splittermain inside the textleft0->setalignment (qt::aligncenter); The text is centered, and the left setting is finished qtextedit *textleft00 = new Qtextedit (Qobject::tr ("Left333 Widget"), splitterRight2); A new Qtexteidt object is filled into the splittermain inside the textleft00->setalignment (qt::aligncenter); The text is centered, and the left setting is finished qtextedit *textleft000 = new Qtextedit (Qobject::tr ("Left333 Widget"), splitterRight2); A new Qtexteidt object is filled into the splittermain. Textleft000->setalignment (Qt::aligncenter); Text Center placed, the left side of the setup is finished//automatically in order from left to right to modify qtextedit *textleft = new Qtextedit (Qobject::tr ("Leave Widget"), Splittermain); A new Qtexteidt object is filled into the splittermain inside the textleft->setalignment (qt::aligncenter); The text is centered, and the left setting is finished qtextedit *textleft22 = new Qtextedit (Qobject::tr ("Left22 Widget"), Splittermain); A new Qtexteidt object is filled into the splittermain inside the textleft22->setalignment (qt::aligncenter); Text Center placed, the left side of the setup finished//Right part of the split window//1, new Create a split add to the main window qsplitter *splitterright = new Qsplitter (qt::vertical, Splittermain); Vertical split Splitterright->setopaqueresize (false); Qtextedit *textup = new Qtextedit (Qobject::tr ("Top Widget"), splitterright); Textup->setalignment (Qt::aligncenter); Qtextedit *textbottom = new Qtextedit (Qobject::tr ("Bottom Widget"), splitterright); Textbottom->setalignment (Qt::aligncenter); Splittermain->setstretchfactor (0, 0); Splittermain->setwindowtitle (Qobject::tr ("Splitter")); Splittermain->show (); This oneThe brake is set to the first column or row according to the sort direction of the program//MainWindow w;//w.show (); return a.exec ();}
So everyone should be able to understand the difference between them!
"QT5 Development and Example" 3, layout management of the split window Qsplitter