"QT5 Development and Example" 3, layout management of the split window Qsplitter

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.