0
외부 파일을 사용하여 테마를 작성하는 방법을 설정하려고합니다. 현재, 나는 파일을 읽고 QString에 넣은 다음 "qApp-> setStyleSheet (string);의 내부에 배치됩니다. 그러나 이것은 보이지 않는 버튼의 배경색을 지정할 때 작동합니다. . 작업 같은 CSS를 너무 QT 디자이너의 내부에 직접 작동Qt 사용자 정의 사용자 테마
는 기능:.
QPushButtons의 배경
void SeniorProject::themer(QString theme_name)
{
qDebug() << theme_name;
QString file = QCoreApplication::applicationDirPath()
+ "/themes/" + "default" + "/theme.style";
qDebug() << "file = " + file;
QFile themeFile(file);
QString themeStyle;
if (themeFile.open(QIODevice::ReadOnly))
{
QTextStream in (&themeFile);
themeStyle = in.readAll();
themeFile.close();
}
else
{
qDebug() << "error";
}
qApp->setStyleSheet(themeStyle);
update();
}
CSS 파일
QPushButton#exit {
color: rgb(220, 0, 0);
border: none;
outline: none;
}
QPushButton#exit:hover {
color: rgb(255, 8, 0);
}
QPushButton#exit:Pressed {
color: rgb(150, 0, 0);
}
QFrame#mainbox QPushButton {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgba(122,188,255,1), stop: 0.44 rgba(96,171,248,1), stop: 1 rgba(64,150,238,1));
border: .1px outset rgb(122, 188, 255);
border-radius:4px;
}
QFrame#mainbox QPushButton:hover {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgba(147,201,255,1), stop: 0.44 rgba(133,190,247,1), stop: 1 rgba(90,163,237,1));
border: .1px outset rgb(122, 188, 255);
border-radius:4px;
}
QFrame#mainbox QPushButton:pressed {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgba(84,169,255,1), stop: 0.44 rgba(66,155,244,1), stop: 1 rgba(45,141,237,1));
border: .1px outset rgb(122, 188, 255);
border-radius:4px;
}
제대로 내 현재 문제, 스타일 시트의 하중을하고 업데이트 (버튼의 테두리가 실제로 내가 원하는 것에 매달린다.) 배경은 작동하지 않는 것 같다. 누구든지 나를 도울 수 있습니까? 감사.
완전한 투명도 (255 중 1)로 어떤 배경을 기대합니까? 'rgba (96,171,248,255)' –
@DmitrySazonov를 시도해보십시오. qt 작성자의 그라디언트에 의해 생성되었습니다. 나는 그것을 255로 설정했지만 문제는 여전히 지속됩니다. 투명도가 1이고 스타일을 제작자에게 직접 지정하면 1로 작동합니다. – seang96