Results 1 to 2 of 2

Thread: Push Button problem!!

  1. #1
    Join Date
    Feb 2006
    Posts
    42
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Push Button problem!!

    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.widt h()));
    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Push Button problem!!

    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.

Similar Threads

  1. How can I put a button onto the qLabel?
    By dwlnet in forum Qt Programming
    Replies: 3
    Last Post: 24th August 2007, 10:47
  2. problem with Tool button n Layout
    By arjunasd in forum Qt Tools
    Replies: 11
    Last Post: 24th July 2007, 22:14
  3. How to ignore Button-Events in Qtopia?
    By Helmut Hönig in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 5th July 2007, 14:24
  4. Replies: 16
    Last Post: 7th March 2006, 16:57
  5. Replies: 7
    Last Post: 15th February 2006, 12:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.