2013-05-31 111 views
4

我正在使用Qt 5.0.1。我想使用樣式表語法來定製小部件的功能和它的元素。Qt樣式表語法不起作用?

但像QLineEdit { color: red }

QPushButton#evilButton:pressed { 
    background-color: rgb(224, 0, 0); 
    border-style: inset; 
} 

一些語法不工作,編譯器會發出錯誤。

我改變了一些語法,並得到answer.for例如:

QPushButton#evilButton { 
background-color: red; 
border-style: outset; 
border-width: 2px; 
border-radius: 10px; 
border-color: beige; 
font: bold 14px; 
min-width: 10em; 
padding: 6px; 

}

轉換爲:

mypushbutton->setStyleSheet("background-color:purple;" 
        "border-style:inset;" 
        "border-width: 4px;" 
        "border-color: green;" 
        "border-radius: 10px;" 
        "font: bold 14px;" 
        "min-width: 10em;" 
        "padding: 6px;" 
        ); 

其實我用另一種功能做that.but我不能不改變第一個代碼,不知道該怎麼辦...我該怎麼辦?我應該用什麼東西或別的東西是問題嗎?我用this頁來學習樣式表的語法。即使我自己的Qt的例子不工作,只是錯誤引發... !!!

+1

沒有人能回答我的問題?這是太有必要了......請幫助 –

+1

請幫忙.... –

回答

7

想你的榜樣,它適用於QT5

Widget::Widget(QWidget *parent) : 
    QWidget(parent), 
    ui(new Ui::Widget) 
{ 
    ui->setupUi(this); 

    this->setStyleSheet(
       "QPushButton#evilButton {" 
       "background-color: red;" 
       "border-style: outset;" 
       "border-width: 2px;" 
       "border-radius: 10px;" 
       "border-color: beige;" 
       "font: bold 14px;" 
       "min-width: 10em;" 
       "padding: 6px; }" 
       ); 
} 

順便說一句我存儲在文件和載入樣式QSS從中

+0

非常感謝你... –

+1

忘了說。您可以爲整個應用程序設置qss qApp-> setStyleSheet(「」); –

+0

再次感謝:) –