2009-10-06 25 views

回答

12

修改喲調色板你純文本編輯。示例程序:

#include <QApplication> 
#include <QPlainTextEdit> 

int main(int argc, char* argv[]) 
{ 
    QApplication app(argc, argv); 

    QPlainTextEdit edit; 
    QPalette p = edit.palette(); 

    p.setColor(QPalette::Active, QPalette::Base, Qt::red); 
    p.setColor(QPalette::Inactive, QPalette::Base, Qt::red); 

    edit.setPalette(p); 

    edit.show(); 
    return app.exec(); 
} 

替換任何你想要的顏色,當然。

+1

請注意,使用此方法將樣式表應用於父項或控件本身將禁用此調色板。有一些有趣的故障排除這只是:) – RandomInsano 2012-08-14 22:26:23

+0

很高興知道,謝謝!我還沒有使用樣式表,所以感謝提前通知。 – Bill 2012-08-15 14:39:23

3

有點混淆,他們稱之爲角色而不是顏色/顏色。

http://doc.trolltech.com/main-snapshot/qwidget.html#setBackgroundRole

提示 - 如果你不能找到一個特定的控制功能,點擊顯示繼承的成員 - 最普通的設置是在QWidget中這是在屏幕上繪製eveything的基礎。

+0

謝謝,但我仍然不知道如何做到這一點... – deuces 2009-10-06 23:51:41

+0

還沒有使用它,但看到這個線程http://lists.trolltech.com/qt-interest/2006-07/thread00174-0 .html – 2009-10-07 00:12:13

0

可能您需要撥打QPlainTextEdit::setBackgroundVisible(true)

0

爲了修改背景,你需要修改QPlainTextEdit的palette並設置背景中可以看到:

myPlainTextEdit->setPalette(QPalette(/*Select the constructor you need*/)); 
myPlainTextEdit->setBackgroundVisible(true); 
3

如果QPlainTextEdit支持樣式表,你可以做這樣的:

myPlainTextEdit->setStyleSheet("background-color: yellow"); 

qApp->setStyleSheet("QPlainTextEdit {background-color: yellow}");