Results 1 to 2 of 2

Thread: Problem displaying image on a customized button

  1. #1
    Join Date
    Dec 2010
    Posts
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Symbian S60 Maemo/MeeGo

    Default Problem displaying image on a customized button

    We are migrating from Qt3 to Qt4. In Qt3, we were using “QButton” as the base class from which we have derived and created our own class “QCButton” to create a customized button with text and image upon it. We used a label whose parent will be the QCButton’s object to set an image on it and with the help of setPaletteBackgroundPixmap() function we were able to set an image and create a customized ellipse-shaped button.

    class QCButton : public QButton
    {
    ...
    };

    In Qt4, we have used QAbstractButton as the base class (since QButton is obsolete) from which we have derived and created our own class “QCButton”.

    class QCButton : public QAbstractButton
    {
    ...
    };


    We have used the below statements as an alternative to the setPaletteBackgroundPixmap():-

    QPalette palette;
    palette.setBrush(label->backgroundRole(), QBrush (pixmap));
    label->setPalette(palette);

    But, using this we are not able to achieve what we want in Qt4 i.e. a customized ellipse-shaped button with a text on it.

    Please advice Qt Experts.
    Thanks in Advance!
    -- Bhavik.

  2. #2
    Join Date
    Dec 2010
    Posts
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Symbian S60 Maemo/MeeGo

    Default Re: Problem displaying image on a customized button

    Ok guys! Got the solution...Basically, in this case we have to reimplement the paintEvent() method. This has become a must in Qt4 since it is a pure virtual function, which was not the case in Qt3.

Similar Threads

  1. Displaying an image
    By seltra in forum Newbie
    Replies: 2
    Last Post: 3rd October 2010, 19:30
  2. as displaying an image in a mdi?
    By Lycus HackerEmo in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2010, 12:14
  3. Displaying image
    By Rui in forum Newbie
    Replies: 1
    Last Post: 20th June 2009, 21:15
  4. problem in Displaying image on push button
    By durgarao in forum Qt Tools
    Replies: 4
    Last Post: 2nd January 2009, 10:27
  5. [problem]displaying image with Pixmap
    By crazy_inf in forum Qt Programming
    Replies: 1
    Last Post: 3rd July 2008, 09:49

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.