PDA

View Full Version : How to set border for QPushButton?



DiamonDogX
4th August 2009, 23:18
I have a QPushButton and would like to put a red border around it with a certain thickness. What's the best way to do this?

izne
4th August 2009, 23:36
right-click it and then "Change styleSheet...", then you can use css to set border.
try this:

border: 1px solid red;

DiamonDogX
5th August 2009, 15:02
How would I do it with C++ code?

burnttoy
5th August 2009, 15:39
Hiya,

p_myPushButton = QPushButton("MyButton", p_parent);
p_myPushButton->setStyleSheet("border:5px solid #ff0000;");

That should do it.

Yours,
Matthew.

DiamonDogX
5th August 2009, 16:35
setStyleSheet() doesn't exist for QPushButton... am I missing something?

schall_l
5th August 2009, 16:44
Look at http://doc.trolltech.com/4.5/qpushbutton-members.html

burnttoy
5th August 2009, 17:28
setStyleSheet() doesn't exist for QPushButton... am I missing something?

Sure it does. It inherits the setStyleSheet member function from QWidget via QAbstractButton.

Good luck!
Matthew.

DiamonDogX
5th August 2009, 17:53
I'm sorry, you are correct. My intellisense was messing up and throwing me off! Anyway, it does set the button's border, but it blanks out the button's background. I tried setting it again after the setStyleSheet call but it did not work, presumably because it's being overwritten by the style sheet settings. I understand I could use "background-color" in the style sheet instead, but is that the only way to do it? Thanks.