- In the processing of QList queues, the most commonly used method is to call the append function to add items and insert items forward. Many people's first impression is to call insert(0,xxx) to insert. In fact, QList completely provides the functions prepend and push to add items forward_ front.
QStringList list; list << "aaa" << "bbb" << "ccc"; //Append later is equivalent to append list.push_back("ddd"); //Append forward is equivalent to prepend list.push_front("xxx"); //Add later list.append("ddd"); //Add forward list.prepend("xxx"); //Specifying the first position insert is equivalent to prepend list.insert(0, "xxx"); //Output QList("xxx", "aaa", "bbb", "ccc", "ddd") qDebug() << list;
- Qt has built-in types related to QList, QMap and QHash, which can be used directly without writing a long type.
//qwindowdefs.h typedef QList<QWidget *> QWidgetList; typedef QList<QWindow *> QWindowList; typedef QHash<WId, QWidget *> QWidgetMapper; typedef QSet<QWidget *> QWidgetSet; //qmetatype.h typedef QList<QVariant> QVariantList; typedef QMap<QString, QVariant> QVariantMap; typedef QHash<QString, QVariant> QVariantHash; typedef QList<QByteArray> QByteArrayList;
-
If the margin interval of Qt layout is not changed, the corresponding default value will be determined according to the system resolution and zoom ratio. For example, the 1080P resolution is 9px, and the 2K resolution becomes 11px. You will find that the programs compiled on the 1080P computer clearly see 6px and 9px. How to get to 2K At 4K resolution, the interval and margin become very large. If you want to keep the same at any resolution, you need to manually reset these values. There is a pit here. For example, the default is 9. You want other resolutions to be 9. You must first change 9 to other values, such as 10, and then 9. This means that it is really changed. If you directly change 9 to 9, it will not change, In the property designer, there is a small arrow on the right. The restored value is also gray. Only when the display is deepened and the restored default value arrow appears, it indicates that you have indeed changed the value.
-
QT's support for high score screen and dpi scaling is becoming more and more mature. In the Qt4 era, the default strategy is to follow the scaling of the system, starting from Qt5 6 began to provide AA_ The property setting of enablehighdpiscaling enables the high score screen. After 5.14, you can also specify the scaling policy. For example, it supports the scaling ratio of floating-point numbers instead of the previous integer multiple. AA is always enabled by default from Qt6_ The enablehighdpiscaling property cannot be cancelled. Many times, we need two modes, one is never to apply high score screen and zoom, and the other is to automatically apply high score screen and zoom.
//Never apply high screen and zoom int main(int argc, char *argv[]) { #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) QApplication::setAttribute(Qt::AA_Use96Dpi); #endif #if (QT_VERSION >= QT_VERSION_CHECK(5,14,0)) QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor); #endif QApplication a(argc, argv); .... return a.exec(); } //Automatic application of high score screen and zoom //There are many methods. By comprehensive comparison, it is the most appropriate to use the configuration file to specify the scaling strategy. //New QT The conf file is placed in the same directory as the executable file [Platforms] WindowsArguments = dpiawareness=0 //Sometimes, if you want users to choose which strategy, you need to turn on the high score screen and just turn QT The conf file can be placed in the same directory as the executable file. Even if it is set in the code not to apply high screen and zoom, it is invalid, and QT is preferred The policy of the conf file.
- Pay attention to the pit of QSS.
- qss is derived from css, which is equivalent to a subset of css. It mainly supports the css2 standard. Many online css3 standards do not take effect in qss, so don't make a fuss.
- qss does not fully support all css2. For example, the official text align document explains that it only supports QPushButton and qpprogressbar. Be sure to see it clearly.
- Sometimes, if you are lazy and say "* {xxx}", you will find that most of them are applications, and a small number or very few do not have applications. You may need to set this - > setstylesheet () in the corresponding form.
- The implementation of qss has priority. If no parent object is specified, it will be applied to all applications, such as {color: #ff0000;} in the form widget In this way, the style will be applied to the widget and all sub objects of the widget. This problem is performed every week in major Qt groups. You will find that various strange things are abnormal. What to do? You need to specify the class name or object name, such as #widget{color:#ff0000;} In this way, only the style will be applied to the widget object. Another writing method is QWidget#widget{color:#ff0000;}, Just want to the form itself, not child controls, button labels, etc QWidget{color:#ff0000;} , See the official instructions for detailed rules.
- qss is OK as a whole. Although there is a BUG with that, treat it with a tolerant heart.