PDA

View Full Version : QPushButton -- Round shape



kishore7771
14th February 2010, 11:37
Hi,

I am using QT 4.1 on windows
I want to my button as round shape (Based on image type).



Please help me!!!

Oleg
14th February 2010, 12:00
It can be simply achieved with style sheets:


button->setStyleSheet("
border-image: url(button.png) 3 10 3 10;
border-top: 3px transparent;
border-bottom: 3px transparent;
border-right: 10px transparent;
border-left: 10px transparent;
");

Sample from Qt Documentation. More here: http://doc.trolltech.com/4.6/stylesheet.html

Lykurg
14th February 2010, 12:46
You can also use QWidget::setMask().

kishore7771
15th February 2010, 04:01
hi I have tried with your example but still its n not working ..here is my code

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton *button = new QPushButton();
button->setStyleSheet("border-image: url(:/button.png) 3 10 3 10;border-top: 3px transparent;border-bottom: 3px transparent; border- right: 10px transparent;border-left: 10px transparent;");
button->show();
return app.exec();
}
button.png is in my application folder and in debug folder also....

kishore7771
15th February 2010, 04:07
Hi I have tried this example ..but its not working ... Button.png is in my App folder and debug folder also...
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel topLevelLabel;
QPixmap pixmap(":/button.png");
topLevelLabel.setPixmap(pixmap);
topLevelLabel.setMask(pixmap.mask());
topLevelLabel.show();
return app.exec();
}

aamer4yu
15th February 2010, 04:17
You could refer to the shaped clock example in Qt Demo,,, instead of the widget, you can have QPushButton.

nish
15th February 2010, 12:40
you have provided the wrong path to button.png.

":/button.png" means the file is located in the qt resource file and not the current/debug dir.