Qt uses qsplitter to implement split windows

Source: Internet
Author: User

Split windows are often used in applications. They can flexibly distribute window la S, which are often used in window design similar to file resource manager. Then, with such an idea, a simple implementation is realized.

 

 

// Main. CPP # include <qapplication> # include <qsplitter> # include <qtextedit> # include <qtextcodec> int main (INT argc, char * argv []) {qtextcodec :: setcodecfortr (qtextcodec: codecforlocale (); qapplication app (argc, argv); // create a main split window and set the direction to qsplitter * mainsplitter = new qsplitter (QT :: horizontal, 0); // create a qtextedit control and set its parent control to mainsplitter qtextedit * leftedit = new qtextedit (qobject: TR ("Left window"), mainsplitter ); // set the align mode of the text in the qtextedit control to center the display of leftedit-> setalignment (QT: aligncenter ); // create a right split window and set its parent control to mainsplitter. Set the direction to Vertical Split Window. Finally, it is split into two upper and lower windows: qsplitter * rightsplitter = new qsplitter (QT: vertical, mainsplitter ); // set whether the bars in the split window are updated in real time when being dragged. If the value is set to true, the bars are updated in real time. If the value is false, only one gray line is displayed. // After the bars are dragged in place and the mouse is clicked display the divider rightsplitter-> setopaqueresize (false ); // start to split it into two upper and lower windows qtextedit * upedit = new qtextedit (qobject: TR ("upper window"), rightsplitter); upedit-> setalignment (QT :: aligncenter); qtextedit * bottomedit = new qtextedit (qobject: TR ("bottom window"), rightsplitter); bottomedit-> setalignment (QT: aligncenter ); // set the number of the control set by the first parameter of the Scalable Control, the control serial number starts from 0 in the order of insertion. // The second parameter is greater than 0, indicating that the control is a scaling control. In this example, set the right split window to the Scalable Control mainsplitter-> setstretchfactor (1, 1); mainsplitter-> setwindowtitle (qobject: TR ("Split Window"); mainsplitter-> show (); Return app.exe C ();}

 

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.