Changed the color and the style of push button and it doesn't work anymore
-
Hey guys
I have a problem , I tried to change the push button's style and color of the font but now I can't press it , I was reading about it but let me just post the code here:
@
GPA_C=new QPushButton;GPA_C->setText("Compute MY GPA!");
GPA_C->setStyleSheet("color:red;font:bold 13px; padding:5px; border-width:2px;border-style:outset;border-radius:12px; border-color:black");@
now it says if you want to fix the click problem you should do this:
@
QPushButton#evilButton:pressed {
background-color: rgb(224, 0, 0);
border-style: inset;
}@
not sure what is he doing here , I created a class to compute the gpa but i can't do what he did here , is there a solution guys ?
-
Try without #evilButton
I guess you didn't use QObject::setObjectName() to give your button an ID
-
not sure if I can understand you , but could you please put some code ? , also what does even mean :
@
QPushButton object:pressed{//..
}
@and can I just fix this another way ?
-
tried to do this:
@
GPA_C->setStyleSheet("color:red;font:bold 13px; padding:5px; border-width:1.5px;border-style:outset;border-radius:12px; border-color:black");
//fix:
GPA_C->setStyleSheet("background-color: rgb(224, 0, 0)");@
it worked but the colors sucks now , also it's not the same as it was , like the font and stuff.
edit: sorry forgot about the pressed thing , but how can I do that now to fix this problem ?
-
Normally you set stylesheets on your qApplication. As a result all your pushbuttons will look the same. Use it like below. Took the example from "the stylesheet docs":http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#style-sheet-usage
@
qApp->setStyleSheet("
QPushButton {
background-color: red;
border-style: outset;
border-width: 2px;
border-radius: 10px;
border-color: beige;
font: bold 14px;
min-width: 10em;
padding: 6px;
}
QPushButton:pressed {
background-color: rgb(224, 0, 0);
border-style: inset;
}
")
@Btw i added lines for readability. If you test line per line it's easier to see what causes a certain effect.
-
Thanks man , I learnt something ^^ , so it's better to make a custom look for anything in the main function instead of the dialog's class ?
it worked by the way , thanks buddy ^^
-
bq. so it’s better to make a custom look for anything in the main function instead of the dialog’s class ?
Yes unless you want every dialog to look different.
Happy i could help.