My QT5 Learning Path (iii)--template Library, tool classes and controls (bottom)

Source: Internet
Author: User
Tags time and date

First, preface

As the last part of the third chapter, we look at the QT controls, and when it comes to controls, it makes people think about the aesthetics and ease of operation of the interface, and then the ease of development. MFC, developed as a Windows interface, has been prevalent for many years, but its drawbacks have been magnified by the advent of other interface libraries, and for a novice who has just learned C or C + + to learn about Windows interface development, MFC's controls and interface designs are abstract and complex, Maybe now you remember that MFC controls redraw more time than other interface libraries, pass the detour, and tune the bug. So, let's see if Qt will give us a different experience.

Ii. introduction of Controls2.1 button Group ( Buttons)

For the display and operation of the button, we show it directly in the way of pictures and code.

Pushbutton: button

Tool button: Tools buttons

Radiobutton: Radio buttons

check box: checkbox

Command linkbutton: Commands to connect buttons

Dialogbutton box: Window pushbutton box

2.1.1 Button instance

1#include"mywidegt.h"2#include <QApplication>3 4 intMainintargcChar*argv[])5 {6 qapplication A (argc, argv);7 Mywidegt W;8     /*set the location and initial size of the main form*/9W.setgeometry ( -, -, $, -);Ten w.show (); One     returna.exec (); A}
main.cpp
1 #ifndef Mywidegt_h2 #defineMywidegt_h3 4#include <QWidget>5 6 classMywidegt: PublicQwidget7 {8 Q_object9 Ten  Public: OneMywidegt (Qwidget *parent =0); A~mywidegt (); - }; -  the #endif //Mywidegt_h
mywidegt.h
1#include"mywidegt.h"2#include <qapplication.h>3#include <qpushbutton.h>4#include <qfont.h>5 6Mywidegt::mywidegt (Qwidget *parent)7 : Qwidget (parent)8 {9     /*Setting the minimum display size of the dialog box*/TenSetminimumsize ( $, -); One     /*Setting the maximum display size for a dialog box*/ ASetmaximumsize (1366,768); -     /*the Pushbutton constructor - Qpushbutton::qpushbutton (const QString & Text, Qwidget * parent = 0) the     */ -Qpushbutton *quit=NewQpushbutton ("Quit", This); -     /*setgeometry (int x, int y, int w, int h) displays a w*h-sized interface starting at coordinates (x, y), with a range not exceeding the size set above*/ -Quit->setgeometry ( +, +, the, -); +     /*set font void SetFont (const Qfont &)*/ -Quit->setfont (Qfont (" Times", -, Qfont::bold)); +  A Connect (quit,signal (clicked ()), Qapp,slot (Quit () )); at  - } -  -mywidegt::~mywidegt () - { -  in}
Mywidegt.cpp

2.2 Input control group (inputs widegets)

The name of each control contained in the input control group (input widegets) is followed by

ComboBox: combo boxes

     Font Combobox: Fonts combo boxes

     Line edit: Row editor

     Text edit: Textual editing

     PlainText edit: Textual editing

     SpinBox: Digital Display frame (spin box)

     Double Spin box: Double spin Box

     Time Edit: Date Editor

     Date Edit: Day editing

     date/timeEdit: Date/Time editing

     Dial: dialing

     Horizontal Scroll Bar: Horizontal scroll bar

     Vertical Scroll Bar: Vertical scroll bar

                  Horizontal slider: Transverse slider

                  Verticalslider: Vertical Slider

                  key SequenceEdit: Shortcut key editing

2.2.1 Control class Introduction

1, Qdatetime class

In Qt5, you can use the Qdatetime class class to get the time of the system. Capture the time and date of the local system through Qdatetime::currentdatetime (). You can return the date and time parts of a DateTime by using date (), and the code below.

1 New Qlabel (); 2 qdatetime *datatime=new  qdatetime (Qdatetime::currentdatetime ()); 3 datalabel->settext (datatime->Date (). toString ()); 4 datalabel->show ();

2, Qtimer class

The use of Timers (Qtimer) is simple and requires only a few steps to complete the timer application.

(1) Create a new timer

Qtimer *time_clock=New Qtimer (parent);

(2) Connect this timer to the signal and slot, using the timer timeout ().

Connect (time_clock,signal (), this, SLOT(Slottimedone ()));

A timeout () signal is sent as soon as the timer time is reached, thereby leaving the Slottimedone () slot to complete a certain thing.

(3) Turn on the timer and set the timing period

There are two ways to turn on the timer, start (int time) and Setsingelshot (true). wherein, the first means that every "time" seconds will restart the timer, you can repeat the departure time, using the Stop () to turn off the timer, and Setsingleshot (true) is only the timer to start one. The former is commonly used in engineering, such as Time_clock->start (2000);

2.3 Show control group (display Widegts)

        Lbael: Label

        Text Browser: TextBox browser

        Graphics View: Graphical views

        Calendar: Calendars

       LCDNumber: LCD Digital

Progress Bar: progress bar

HorizontalLine: Horizontal line

VerticalLine: Vertical

Qdeclarativeview: Exposing the Data View to QML

        qquickwidegt: Quick Layout

qwebview: Web View

2.3.1 Control class Introduction

(1) Graphics view corresponds to Qgraphicsview class

(2) The Text browser corresponds to the Qtextbrowser class. The Qtextbrowser class inherits from the Qtextedit, and the content of the opposite is not changed, but it also has the function of linking text relative to Qtextedit.

2.4 Space Interval Group (spacers)

Horizontal Spacer: Horizontal interval

Vertical Spacer: Vertical interval

2.5 Layout Management Group (Layouts)

Verticallayout: Vertical layouts

Horizontallayout: horizontal (horizontal) layouts

Grid layout: Grid layouts

Form layout: Table layouts

2.6 Container Group (Containers)

Group box: Groups Boxes

ScrollArea: scrolling region

tool Box: Toolbox

Tab widget: Label widget

stacked widegt: Stacked Parts

Frame: Frames

Widgets: Widgets

mdiarea: MDI Zone

      Dock widget: Docking widget

      qaxwidget: ActiveX controls that encapsulate Flash

2.7 Project View group (item views)

List view: Inventory views

tree view: TreeView

tabelview: Table View

column View: Columns views

2.8 Project Control Group (item Widgets)

List widegt: Manifest control

Tree widegt: TreeView control

tabel widegt: Table control

Three, a comprehensive sample

1 #ifndef Dialog_h2 #defineDialog_h3 4#include <QDialog>5 6 namespaceUi {7 classDialog;8 }9 Ten classDialog: PublicQdialog One { A Q_object -  -  Public: the     ExplicitDialog (Qwidget *parent =0); -~Dialog (); -  - Private: +Ui::D Ialog *UI; - PrivateSlots: +     voidon_lineedit_textchanged (); A }; at  - #endif //Dialog_h
1#include"dialog.h"2#include"ui_dialog.h"3 4Dialog::D ialog (Qwidget *parent):5 Qdialog (parent),6UiNewUi::D ialog)7 {8UI-&GT;SETUPUI ( This);9     /*only the first character is allowed to enter the uppercase and lowercase letters, followed by a number other than 0, then the 0~2 bit can be 0*/TenQregexp RegExp ("[a-za-z][1-9][0-9]{0,2}"); One     //sets the validator, which is the input of only the type of the regular requirement AUi->lineedit->setvalidator (NewQregexpvalidator (REGEXP, This)); -Connect (ui->okbutton,signal (clicked)), This, SLOT (Accept ())); -Connect (ui->cancelbutton,signal (clicked)), This, SLOT (Reject ())); the     - } -  -dialog::~Dialog () + { -     DeleteUI; + } A  at voiddialog::on_lineedit_textchanged () - { -     //When the edit box detects an input, set the OK button to available -Ui->okbutton->setenabled (ui->lineedit->hasacceptableinput ()); -}
Iv. Summary

  All right, here we go. The content of Template Library, tool class and control is basically finished, the detailed content and focus will be mentioned in the later study, finally hope that they can learn in depth, also hope that readers can read the harvest.

My QT5 Learning Path (iii)--template Library, tool classes and controls (bottom)

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.