QT usage miscellaneous notes

1. The character encoding conversion function of QString is a reference value, such as: toLocal8Bit(), and the returned temporary object cannot be used for operation. Otherwise, if the new object is not saved, the temporary object will be destroyed by itself after the execution of this line of code. , resulting in an error in subsequent code usage.

    QString only_a_test = "imya kb";
    const char * will_error = only_a_test.toLocal8Bit().constData();   // 这行执行完,will_error变量将是不确定的值。

If you need to use it, you need to save the newly defined QByteArray variable to save the temporary object returned by toLocal8Bit(), which can be used for subsequent codes.

QString only_a_test = "imya kb";
QByteArray new_save_str = only_a_test.toLocal8Bit();
const char * it_is_right = new_save_str.constData();

2. Action, button, stylesheet settings in QToolBar: Format: QToolBar QToolButton{...}
QToolBar is indirectly inherited from QWidget, so QToolBar is essentially a QWidget, if you only use QToolBar{...} for stylesheet settings, yes It can't be applied to the action in QToolBar. I didn't read it in the QT document. I don't know what QT thinks, or I can't find it. Does anyone know where the QT file is, can tell me.
Here's an example:

        "QToolBar{background-color:rgb(39, 39, 39); color:rgb(204, 204, 204);}"
        "QToolBar QToolButton{background:rgb(39, 39, 39); color:rgb(204, 204, 204);}"   /*这个就是控制 action的设置*/
        "QToolBar QToolButton:hover{background-color:rgb(83, 83, 83);}"
        "QToolBar QToolButton:checked{background-color:rgb(83, 83, 83);}"
        "QToolBar QLabel{background-color:rgb(39, 39, 39);}"  /**/

3.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324525301&siteId=291194637