Dock widgets and toolbars)

Source: Internet
Author: User

The Dock control can be docked in the qmainwindow or floating as an independent window. Qmainwindow provides four parking controls: top, bottom, left, right. Microsoft Visual stadio program and QT linguist program use a large number of docked windows to implement more complex user interfaces. In QT, the window that can be docked is an instance of qdockwidget. Figure 6.13. Qmainwindow With a dock widget

Each docked control has a title bar. You can drag the title bar to move the window from one area to another. Drag the title bar to move the window to an area that cannot be docked, and the window floats into an independent window. A floating window is always on the top of the main window. You can click the close button on the title bar to close the qdockwidget. Call qdockwidget: setfeatures () to set these attributes. In earlier versions of QT, the toolbar is also used as a Dock Control and can be placed in any dock area. From qt4, the toolbar has its own position and cannot be moved any more. If you need a tool bar that can be docked, we can put it in qdockwindow. Figure 6.14. Qmainwindow 'S dock and toolbar Areas

The four corners represented by the dot line can belong to any adjacent docked area. For example, call qmainwindow: setcorner (QT: topleftcorner, QT: leftdockwidgetarea) to use the upper left corner as the dock area on the left. The following code places an existing control (such as qtreewidget) in the qdockwidget, and stops at the right of the widget. Qdockwidget * shapesdockwidget = new qdockwidget (TR ("shapes"); shapesdockwidget-> setwidget (treewidget); shapesdockwidget-> setallowedareas (QT: Alert | QT: Alert ); adddockwidget (QT: rightdockwidgetarea, shapesdockwidget); The setallowareas () function determines the position where the control can be docked. The code above allows you to drag the window to the dock area on the left or right. The vertical controls are sufficient to display a tree control. If no parking area is specified, you can drag the control to any four parking areas. The following code creates a toolbar that contains a qcombobox, qspinbox, and some qtoolbuttons. The code is part of the constructor of the qmainwindow subclass: qtoolbar * fonttoolbar = new qtoolbar (TR ("font"); fonttoolbar-> addwidget (Inline); fonttoolbar-> addwidget (sizespinbox); fonttoolbar-> addaction (boldaction ); fonttoolbar-> addaction (italicaction); fonttoolbar-> addaction (underlineaction); fonttoolbar-> setallowedareas (QT: toptoolbararea | QT: bottomtoolbararea); addtoolbar (font Toolbar); if we need to restore all the dock controls and toolbar locations during the next running of the program, we can use code similar to saving the qsplitter status: void mainwindow: writesettings () {qsettings settings ("Software Inc. "," icon Editor "); settings. begingroup ("mainwindow"); settings. setvalue ("size", size (); settings. setvalue ("State", savestate (); settings. endgroup ();} void mainwindow: readsettings () {qsettings settings ("Software Inc. "," icon Editor "); settings. begingroup ("mainwindo W "); resize (settings. value ("size "). tosize (); restorestate (settings. value ("state "). tobytearray (); settings. endgroup ();} qmainwindow provides a context menu that lists all the windows and toolbar that can be docked. You can use this menu to close the display of the dock window and toolbar. Figure 6.15. A qmainwindow context menu

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.