3

I try to write a simple Player with Qt.

I try to set Play button look like this

pushbutton style

Use stylesheet or use a QPixmap like a button.

My code is

playCtrl = new QPushButton(this);
playCtrl->setIcon(QIcon(QPixmap(":/icons/icons/play.png")));
playCtrl->setIconSize(QSize(150, 150));
playCtrl->setStyleSheet("QPushButton{background-image:url(:/icons/icons/play.png)}"); 

but when I run my code, I just got this:

enter image description here


I'm very happy to say, I had solve this problem.

Just use this:

playCtl = new QPushButton(this);
playCtl->setIcon(QIcon(QPixmap(":/icons/icons/player_play.png")));
playCtl->setIconSize(QSize(32, 32));
playCtl->setStyleSheet("QPushButton{border: none;outline: none;}");

enter image description here

midCat
  • 123
  • 4
  • 13
  • What have you tried? For good answers, it is best to post some code and describe how it behaves differently from what you expect, see also [The FAQ](http://stackoverflow.com/faq). In your case, did you try to use `QPushButton::setIcon()`? – Andreas Fester Mar 28 '13 at 11:10
  • 1
    use photoshop to make the image; then set it as the image of the button. – tianz Mar 28 '13 at 11:19
  • But my button still have a frame.. – midCat Mar 28 '13 at 11:21
  • 1
    can you try playCtrl->setFlat(true)? I found it on google but not sure about it since i currently don't have qt installed. – tianz Mar 28 '13 at 11:27
  • QPushButton::setFlat(bool); – Amartel Mar 28 '13 at 11:28
  • Ok you solved it. That's really nice! – tianz Mar 28 '13 at 11:40
  • You could also implement your own button subclassing from QAbstractButton and reimplement paintEvent(). Then you don't have to try that hard to turn off unwanted UI elements such as borders and bevel. It would avoid surprises when on other platforms/using different styles. – Frank Osterfeld Mar 28 '13 at 21:03
  • @midCat when you solve the problem you should post it as an answer and accept it so that others can see that your problem is solved stackoverflow.com/help/self-answer – Erik May 09 '15 at 18:37

0 Answers0