-1
的main.cpp如何在應用程序運行時通過apllication重置樣式表文件?
int main(int argc, char *argv[]){
QApplication app(argc, argv);
QFile data("://stylesheet.qss"); // this is a stylesheet file in images.qrc file
QString style;
if (data.open(QFile::ReadOnly))
{
QTextStream styleIn(&data);
style = styleIn.readAll();
data.close();
app.setStyleSheet(style); // I want this line to restart with different style-sheet file
}
app.setWindowIcon(QIcon("://images/BEL.jpg"));
MainWindow w;
w.setFixedSize(500,350);
w.showMaximized();
return app.exec();}
theme.cpp
theme::theme(QWidget *parent) :
QDialog(parent),
ui(new Ui::theme) {
ui->setupUi(this);
ui->apply_button->setDefault(1);
QButtonGroup *radio=new QButtonGroup;
radio->setExclusive(true);
radio->addButton(ui->radio_blue,2);
radio->addButton(ui->radio_grey,3);
connect(radio,SIGNAL(buttonClicked(int)),this,SLOT(function(int)));}
theme::~theme()
{
delete ui;
}
void theme::on_pushButton_2_clicked()
{
this->close();
}
void theme::function(int value)
{ if(value==2){
qDebug()<<"blue";}
else if(value==3){
qDebug()<<"green";}
else
qDebug()<< "error";
}
我的main.cpp和theme.cpp和許多其他文件。我的主題窗口中有兩個單選按鈕。我有兩個灰色和藍色的樣式表文件。當我檢查任何按鈕時,它應該適用於所有應用程序,如main.cpp中所示。
問題是,當我啓動應用程序它只適用文件一次。但是當我查看其他按鈕時,我想讓它運行。無論如何,這樣我現在可以在main.cpp中按下特定的按鈕,並且可以重新使用該按鈕的樣式表文件來重新啓動應用程序?
你確切的問題是什麼?你無法讀取文件?你不能應用樣式表? –
我得到了我的問題的解決方案 –
所以,提供一個答案或刪除您的問題 –