PDA

View Full Version : Push Button problem!!



Seema Rao
22nd April 2006, 12:25
Hi all,
I am trying to create round shaped/smooth edged push buttons with bitmap on It. Here is the code I had written,

#include <QtGui>
#include <QApplication>
#include <QPushButton>
#include <Qt>

QPushButton *customButton(QString,QString );

int main(int argc, char *argv[]){


QApplication myapp(argc,argv);
QWidget *mywidget = new QWidget;
QPushButton *first=customButton("f1u7.png", "first");
QPushButton *second=customButton("f1u8.png","second");

QHBoxLayout *mylayout= new QHBoxLayout(mywidget);
mylayout->addWidget(first);
mylayout->addWidget(second);
mywidget->setLayout(mylayout);

mywidget->show();

return myapp.exec();

}
QPushButton *customButton(QString str,QString str1)
{
QPushButton *pushButton= new QPushButton;

pushButton->setGeometry(10,10,100,100);
pushButton->clearMask();
pushButton->setBackgroundRole( QPalette::Base);

QPixmap mypixmap; mypixmap.load(str);

QBitmap bm = mypixmap.createHeuristicMask();
pushButton->setFixedSize( mypixmap.width(), mypixmap.height() );
pushButton->setMask( bm );
pushButton->setIcon(mypixmap);
pushButton->setIconSize(QSize(mypixmap.height(),mypixmap.width ()));
pushButton->setToolTip(str1);
return pushButton;

}
Bitmap appears on the button but with strange visual effect. Corners of button looks strange and some times dots appear on the border of the button. Would some body explain, the right way of doing it?

Thanks in advance,
Seema Rao

wysota
22nd April 2006, 16:31
It might prove simpler to subclass QPushButton and reimplement its paintEvent. It depends what exact effect you want to achieve and if you want to follow the style of the rest of the application or not necessary.