Qt style sheets bugs?

三世轮回 提交于 2019-12-06 18:27:45

问题


I have a many bugs at simple QSS(Qt style sheets). Is it bugs of Qt?

Example:

Style sheets:

#check1 {
  color: red                  //didn't work here
}

#check2 {
  color: red;                 //but work here
  background-color: black
}

#label1 {
  color: blue;
  text-decoration: underline  //work fine here
} 

#label2:hover {
  color: blue; 
  text-decoration: underline  //but didn't work here
}

Sources:

#include <QtGui>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    app.setStyleSheet(" #check1 {color: red} \
                        #check2 {color: red; background-color: black}  \
                        #label1 {color: blue; text-decoration: underline}  \
                        #label2:hover {color: blue; text-decoration: underline}");
    QWidget w; w.setFixedSize(120,130);

    QCheckBox check1("checkbox1",&w);
    check1.setObjectName("check1");
    check1.move(10,0);

    QCheckBox check2("checkbox1",&w);
    check2.setObjectName("check2");
    check2.move(10,30);

    QLabel label1("label1", &w);
    label1.setObjectName("label1");
    label1.move(10,60);

    QLabel label2("label2", &w);
    label2.setObjectName("label2");
    label2.move(10,90);
    w.show();

    return app.exec();
}

qt 4.7.3-3; arch linux; gnome 3 fallback mode


回答1:


For the first checkbox, the problem is somewhere in the Gtk+ style:

QLabel, QPushButton or QCheckBox don't support font changes (including text-decoration) in the :hover pseudo-state css selector. The simplest widget that does seems to be QToolButton (which could be used to replace the QLabels if you really need that).
Palette changes (foreground and background colors and styles) for that state are supported by all the widgets.




回答2:


I can't say what the issue with your checkbox is, but the following tidbit can be found in is according to Qt's style sheet reference (I can't find it online, but it's in Qt Assistant)

QLabel supports the box model. Does not support the :hover pseudo-state.

In other words, QLabel:hover is not supported.




回答3:


Instead of

// some comment

use

/* some comment */

. I guess they chose the latter form as it is immune to newline-breakage.

Apart from that, if it is still not okay, then it seems you've run into bugs: https://bugreports.qt-project.org//browse/QTBUG-4307 .

As a workaround for setting only the text color, try out

#check1:hover { color:red; background-color:transparent; }

which worked for me.




回答4:


Shouldn't

color: red

be

color: red;

?

Missing semicolons a few places in your posted code.



来源:https://stackoverflow.com/questions/7166403/qt-style-sheets-bugs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!