Qt learning Summary-ui (II), qt learning Summary-ui

Source: Internet
Author: User
Tags qt designer

Qt learning Summary-ui (II), qt learning Summary-ui
Qccs defines rounded corners

Border-radius: 10px;

To define a rounded corner for a specific position, for example:

Upper left corner: border-left-top-radius: 10px;

Bottom right role: border-right-bottom-rasius: 10px;

 

Translucent Effect

You only need to use rgba (100,100,100, 40) in css to represent the color.

 

Add icons for executable files

1. Create a file: The finename. rc file name does not matter, as long as the suffix is rc.

2. Edit the new file and enter the following content:

IDI_ICON1 icon discardable "icofire. ico"

"Icofire. ico" is the icon file path. Note that the path is relative to the current resource file.

3. After re-compilation, you can see the executable file icon.

 

Load the font file ttf

Add the following code to the mian function:

1 int main (int argc, char * argv []) 2 {3 QApplication a (argc, argv ); 4 5 // Add the font file 6 int d = QFontDatabase: addApplicationFont (": // DS-DIGIB.TTF") from the resource file "); 7 8 // get the font name 9 QStringList list = QFontDatabase: applicationFontFamilies (d); 10 foreach (QString f, list) {11 qDebug () <"font family: "<f; 12} 13... 14}

Print result:

1 font family: "DS-Digital"

You can see from the printed results that the loaded fonts are called DS-Digital.

Font:

1 QFont f;2 f.setFamily("DS-Digital");3 f.setPointSize(25);

 


How to Use the Ui file in Qt

The first step is to create a ui file. First, you should use Qt Designer to draw your own interface and coexist with myform. ui (here, myform can be replaced by your favorite name ). Pay attention to the following points when creating your own interface file: 1. Remember the name of the ui file, because the code generated by uic will exist in ui_myform.h. 2. Remember the name of the object in the main form, because the class names provided by the ui file are named by this form. 3. Pay special attention that the base class selected by your form must be compatible with the form class in your code. 4. Remember to give each the control to be accessed later makes a meaningful and memorable object name, because the controls provided by the ui file are named after these object names, it is very easy to use your ui file in code. Step 2: add the ui file to the project. You only need to modify the pro file and add FORMS + = myform. the uiqmake-project command can also identify and add files with the suffix "ui" to the project. Step 3: reference the ui file in the Code. There are three methods to use the ui file officially introduced: direct reference, single inheritance, and multi-inheritance. The first method is not practical. Let's take a look at the example in the document. The second and third methods have no essential difference and can be used as a class. Here we will focus on the introduction. The ui file is eventually translated into standard C ++ code and saved to. in the H file, this process is only performed after calling make. Therefore, you cannot see the ui_myform.h file initially. This header file is generated only after the make process. But it doesn't matter. Without this file, we can still write the correct code. In simple terms, the single inheritance method is to first customize a subclass (called MyForm) in the Code. This class must be derived from the form class (or its compatible subclass) corresponding to the form; use the class generated by the ui to define the member variables in a class (myui in the following text ). In this way, variables and functions in myui and myui can be directly called in the MyForm constructor, which is convenient to use. For example, there is a ui file named myform. ui: the form defined in the ui file is named BigWidget, and a single-row editing control named lineeditName: // myform is placed on it. h # include "ui_myform.h" class MyForm: public QWidget {Q_OBJECTpublic: MyForm (QWidget * parent) {myui. setupUi (this);} private: Ui: BigWidget myui; private: void my_function () ;}; the preceding simple class declaration is the best example of the first three points mentioned above, compare the text description of the key points with the specific code to understand the meaning. Another interesting thing is that the class provided by the ui file is included in the name space named Ui, in this way, The namespace of the ui file is separated from the user's code to avoid conflicts between the two. Correspondingly, when writing code, we should also pay attention to using the "ui:" method to reference classes in the Ui file. Let's take a look at the cpp file // myform. cpp # include <QMessageBox> # include "myform. h "void my_function (void) {QMessageBox: information (this," Name ", myui. lineeditName-> text ();} a function is written here to illustrate how to call the control defined in the ui file in the Form class. This code is very simple and I will not explain it much. With the foundation of single inheritance, learning multi-inheritance is a piece of cake. You can see the following code. // My... the remaining full text>

How to Use qt to create a nice ui

I don't know what you mean. Do you have specific requirements?
Zun first ~~~
Well, you need to make a good-looking ui. First, there is design and second implementation. The QT Foundation should be solid.
// Basic metrics ------------------------------------------------------------------------------------
Aesthetics. That is, you must be able to design an interface that looks nice to you and everyone feels nice to you ~ Otherwise, the technology will be cool, and how well the functions will be implemented will make everyone feel ugly.
Be familiar with various widgets in the ui. You can familiarize yourself with all the control attributes that you find useful in Qt. This is very important. The economic foundation determines that upper-layer buildings can be implemented only with controls. For example, we had to build an interface containing several lines of QLineEdit. It was too troublesome to write the code. Then we accidentally found that we could plug the control into QTableWidget, hide the header, and border the interface, the results are the same, and they are convenient ~~ Sometimes, the attributes that people bring are more perfect than those that you write ~
// Some -------------------------------------------------------------------------
Customize the title bar. The nice-looking Dialog is still a system. You can look at the anti-virus software you use. You can also use QT for that interface. The most popular one is the Qt implementation 360 interface in the Forum, you can refer to how to create a beautiful title bar.
StyleSheet Qt style sheet. What if there is no eye-catching color and response matching on the nice-looking interface? Complex attributes in the style sheet, multiple colors will open your eyes! (I have only scratched the surface, and I should have more functions than that)
Rewrite interface class. Some interface controls you want to use, but you still want to modify them to improve a class that inherits from the control and write what you need ~~

That's all I think of for the moment. The keyboard in the house is broken, and the hand is sour.


Related Article

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.