-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中按下特定的按钮,并且可以重新使用该按钮的样式表文件来重新启动应用程序?
你确切的问题是什么?你无法读取文件?你不能应用样式表? –
我得到了我的问题的解决方案 –
所以,提供一个答案或删除您的问题 –