Qt gui@ Learning Log

Source: Internet
Author: User

Day 1:

QT class:

It is best to understand a class from its Class code implementation.

This diagram shows that there are several important classes that need to be studied: qt/qevent/qobject/qwidget/.

Qapplication: (more complex and very common)

    • It initializes the application with the user's desktop settings, such as palette (), font (), and Doubleclickinterval (). If the user changes the global desktop, for example through some control panels, it keeps track of those properties.
    • It performs event handling, which means it receives events from the lower window system and assigns them to the relevant widgets. By using Sendevent () and postevent (), you can send your own events to the widgets.
    • It parses the command-line arguments and sets the internal state based on them. For more information on this, refer to the following constructor documentation.
    • It defines the look and feel of the application encapsulated by the Qstyle object. In the running state, it can be changed by SetStyle ().
    • It specifies how the application assigns colors. Please refer to Setcolorspec () for more information.
    • It defines the default text encoding (refer to Setdefaultcodec ()) and provides a localized string that is visible through the translate () user.
    • It provides some magical objects like desktop () and clipboard ().
    • It knows the application's window. You can use Widgetat () to ask which widget exists at a certain point, get a list of Toplevelwidgets () (top-level widgets), close all Windows through Closeallwindows (), and so on.
    • It manages the mouse cursor handling of the application, please refer to Setoverridecursor () and setglobalmousetracking ().
    • On the X Window System, which provides functions for refreshing and synchronizing traffic flows, refer to Flushx () and Syncx ().
    • It provides complex dialogue management support. This allows the application to end well when the user logs off, undo the shutdown process if it cannot be terminated, and even preserve the state of the entire application for future conversations. Please refer to issessionrestored (), SessionId (), CommitData () and SaveState () for more information.

App.exec ();

Enters the main event loop and waits until exit () is called or the main window part is destroyed, and the return value is set to exit () (if exit () is called by Quit (), 0).

Qlabel: Provides the ability to display text and pictures. You can also set the display format and so on.

Qobject: is the base class for all Qt objects.

Qmainwindow: Provides a main application window with a menu bar, an anchor window (such as a toolbar), and a status bar. The main window is typically used to provide a large central widget (such as text editing or drawing the canvas) along with the surrounding menus, toolbars, and a status bar. Qmainwindow is often inherited because it makes it easier to encapsulate central parts, menus, and toolbars, as well as window states. Inheritance makes it possible to create slots that are called when a user taps a menu item or a toolbar button.

The Qwidget:qwidget class is the base class for all user-interface objects.

    • A widget is an atom of the user interface: it receives mouse, keyboard, and other events from the window system and plots its own performance on the screen. Each widget is a rectangle, and they are arranged in the z-axis order. A widget can be partially covered by its parent window part or by a window part in front of it.
    • Qdialog is the most common top-level window. Widgets that are not embedded in a parent widget are called top-level widgets. Typically, a top-level widget is a window with frames and title bars (although it may not be possible to create a top-level window part if a certain window part tag is used). In Qt, Qmainwindow and different qdialog subclasses are the most common top-level windows.
    • A widget that does not have a parent widget is always a top-level window part.
    • A non-top-level window part is a child window part. They are child windows in their parent window part. You usually cannot discern a child widget from their parent widget at a visual angle. The vast majority of other widgets in QT are useful only as sub-widgets. (It is also possible to use a button as a top-level widget, but most people prefer to put their buttons in other buttons, such as Qdialog.) )
    • Qwidget has a number of member functions, but some of them have a small amount of direct functionality: For example, Qwidget has a font property, but it never does. There are a lot of subclasses that inherit from it that provide real-world functionality, such as Qpushbutton, Qlistbox, Qtabdialog, and so on.

C + + parent class and subclass conversion

Qmainwindow *MW = new Qmainwindow; Qtextedit *edit = new Qtextedit (MW, "editor"); Child class type cast to parent class type
MW is the Qmainwindow type, which inherits from Qwidget, but the MW seat requires Qwidget*edit->setfocus (); Mw->setcaption ("Main window");mw-> Setcentralwidget (edit); Mw->show ();

Subclasses can be converted to a parent class, but the parent class cannot be converted to subclasses (the process of thinking about inheritance is understood); The subclass is converted to the parent class, and the subclass-specific data is lost.

If the parent object's reference points to an object that is actually a subclass, the reference to the parent object can be coerced into a reference to the child class object. Such as:
The parent p=new Son ()//Parents object refers to the object that points to the child class;
Son s= (son) p; -Correct

Parent p=new ()//Parental object refers to the object that points to the parent class;
Son s= (son) p; --Error

Qt [email protected] learning Log

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.