Proprietary stylesheet for a button in external stylesheet file
-
Hi
I'm loading an external style sheet file for my form.
this is code :
@
QPushButton{
background: transparent;
color: white;
}QPushButton QPushButton:on{
background: transparent;
color: white;
}
@How can i set this style sheet for just one button with name btngo ?
-
Try
@
qApp->findChild<QPushButton*>("btngo")->setStyleSheet("...style...");
@If you have multiple "btngo"-buttons that should all have that stylesheet, use findChildren and iterate over the list.
-
@
qApp->findChild<QPushButton*>("btngo")->setStyleSheet("QPushButton{background: transparent; color: white;}QPushButton QPushButton:pressed{background: transparent;color: white;}");
@
no work!any way to explain it in style sheet file?
-
Is the correct pointer returned by findChild? Does the styleSheet work when using it on the variable (i.e. ui->btngo->setStyleSheet or similar?
-
No,i want to define it in .qss file in external style sheet
ui->btngo->setStyleSheet(); is working right
-
So in this case
@
qApp->findChild<QPushButton*>("btngo")
@
seems to return the wrong button (or none at all). Is the button really called btngo? What's returned by ui->btngo->name()?
Further, try using the findChild not on qApp but on your main window (or the window which contains the button) instead.//EDIT: Ah now I think I get it, you want to define inside the CSS file which button name to style, right? I don't know of a Qt-way to do that. Maybe you should parse the CSS file yourself and add some extended syntax which then uses the findChild function to apply it to a QWidget with the specified name.
-
[quote author="DerManu" date="1338837244"]So in this case
//EDIT: Ah now I think I get it, you want to define inside the CSS file which button name to style, right? I don't know of a Qt-way to do that. Maybe you should parse the CSS file yourself and add some extended syntax which then uses the findChild function to apply it to a QWidget with the specified name.[/quote]yes right.
i fixed it with parsing string.
thanks a lot.