QT 使用杂记

1.QString 的 字符编码转换函数是引用取值,如:toLocal8Bit(),不能使用返回的临时对象进行操作,否则,如果不进行新对象保存,此临时对象会在本行代码执行结束后自行销毁,导致后续代码使用出错。

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

如果需要使用,需要保存新定义 QByteArray 变量,用于保存 toLocal8Bit(),返回的临时对象,才能用于后续代码的使用。

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

2.QToolBar 的 中的action ,按钮,stylesheet 设置:格式:QToolBar QToolButton{...}
QToolBar 间接继承于 QWidget ,所以QToolBar本质上是一个 QWidget,如果只使用 QToolBar{...} 进行stylesheet 设置,是不能作用到 QToolBar 中的 action 上的,这一点 QT文档里我没翻着,不知道QT咋想的,或者是我没找到,有谁知道QT文件哪里有,可以告诉我。
来个例子:

        "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.

猜你喜欢

转载自blog.51cto.com/13435030/2104938