QWebView plain text document style
In my app I have several places that use a QWebView
and load the content from the server. In addition the app allows the user to select a default or a dark theme. When the content-type of the document to display is text/plain and the application theme is set to dark, the text is displayed as black text on a black background. I can only see the text if I highlight it. text/html documents work well with either theme.
Ideally when the dark theme is selected I want to display white text on a black (or dark gray) background. I have not been able to figured out how to do this.
Here is the code I currently use to set up the theme:
if(Theme == "dark")
{
app.setStyle(QStyleFactory::create("Fusion"));
QPalette darkPalette;
darkPalette.setColor(QPalette::Window, QColor(88,88,88));
darkPalette.setColor(QPalette::WindowText, Qt::white);
darkPalette.setColor(QPalette::Base, QColor(25,25,25));
darkPalette.setColor(QPalette::AlternateBase, QColor(88,88,88));
darkPalette.setColor(QPalette::ToolTipBase, Qt::white);
darkPalette.setColor(QPalette::ToolTipText, Qt::white);
darkPalette.setColor(QPalette::Text, Qt::white);
darkPalette.setColor(QPalette::Button, QColor(53,53,53));
darkPalette.setColor(QPalette::ButtonText, Qt::white);
darkPalette.setColor(QPalette::BrightText, Qt::red);
darkPalette.setColor(QPalette::Link, QColor(42, 130, 218));
darkPalette.setColor(QPalette::Highlight, QColor(150, 200, 255));
darkPalette.setColor(QPalette::HighlightedText, Qt::black);
app.setPalette(darkPalette);
} else {
Theme = "default";
app.setStyle(QStyleFactory::create("Fusion"));
app.setPalette(DefaultPalette);
}
// load the style sheet
QFile file(":/themes/" + Theme + "theme.css");
file.open(QIODevice::ReadOnly);
const QByteArray theme = file.readAll();
app.setStyleSheet(theme);
The default theme style sheet is blank and the dark style sheet is:
QToolTip {
color: #ffffff;
background-color: #2a82da;
border: 1px solid white;
}
QScrollBar:horizontal {
border: 1px solid grey;
background: #606060;
height: 20px;
margin: 0px 20px 0px 20px;
}
QScrollBar::handle:horizontal {
border: 1px solid #909090;
background: #303030;
min-width: 20px;
}
QScrollBar::add-line:horizontal {
border: 1px solid #909090;
background: #303030;
image: url(:/themes/themes/dark/sbright.png);
width: 20px;
subcontrol-position: right;
subcontrol-origin: margin;
}
QScrollBar::sub-line:horizontal {
border: 1px solid grey;
background: #303030;
image: url(:/themes/themes/dark/sbleft.png);
width: 20px;
subcontrol-position: left;
subcontrol-origin: margin;
}
QScrollBar:vertical {
border: 1px solid grey;
background: #606060;
width: 20px;
margin: 20px 0 20px 0;
}
QScrollBar::handle:vertical {
border: 1px solid #909090;
background: #303030;
min-height: 20px;
}
QScrollBar::add-line:vertical {
border: 1px solid #909090;
background: #303030;
image: url(:/themes/themes/dark/sbdown.png);
height: 20px;
subcontrol-position: bottom;
subcontrol-origin: margin;
}
QScrollBar::sub-line:vertical {
border: 1px solid grey;
background: #303030;
image: url(:/themes/themes/dark/sbup.png);
height: 20px;
subcontrol-position: top;
subcontrol-origin: margin;
}
链接地址: http://www.djcxy.com/p/39316.html
上一篇: 在qt 4信号和插槽中被clicked()和clicked(bool)困惑
下一篇: QWebView纯文本文档样式