ShellRox
ShellRox

Reputation: 2602

PyQt4: How to make Icon bigger than QPushButton? (Pixmap Buttons)

I am struggling on making a Pixmap button, since there was no other option (That i knew) i tried using QIcon.

The picture that i wanted as button, was not fully square, i wanted to only show the pixmap, but with it still having a button function (Signals connecting to slots, etc.).

When i tried to make the Icons size equal to button, Icon would go up and it wouldn't fit in at all, and button would show outside of icon.


So the Question is:

How can i make icon greater than a QPushButton? so only icon would show and it would still have icon functions.

If this is over Icon borders, then is it any other way making Pixmap buttons?

Upvotes: 1

Views: 8552

Answers (2)

cigar huang
cigar huang

Reputation: 182

I use PySide. Maybe the codes are similar

btn = QPushButton('')
btn.setIcon(QPixmap(image path))
# adjust width and height to fit the size of button.
btn.setIconSize(QSize(width, height))   
# set zero border.
btn.setStyleSheet('QPushButton{border: 0px solid;}')

Upvotes: 4

danidee
danidee

Reputation: 9634

You can simply use css to achieve that with the background-image property like this and also set the border to 0

btn.setStyleSheet("background-image: url('image.jpg'); border: none;")

Upvotes: 4

Related Questions