Discussion Board

Results 1 to 8 of 8

Thread: QPushButton

  1. #1
    Regular Contributor damodharan's Avatar
    Join Date
    Oct 2008
    Posts
    323
    Dear All,
    I want to create push buttons, and be able to have several images for them:
    1) Up, enabled
    2) Down, enabled
    3) Up, disabled
    4) Down, disabled.

    but i am getting only up enabled image.. remaining options are not working .
    any one have idea on this ?

  2. #2
    Nokia Developer Moderator divanov's Avatar
    Join Date
    Oct 2009
    Posts
    4,326
    Are you using QAbstractButton::setIcon()?

  3. #3
    Regular Contributor damodharan's Avatar
    Join Date
    Oct 2008
    Posts
    323
    no

    QPushButton->SetIcon(icon);

  4. #4
    Nokia Developer Moderator divanov's Avatar
    Join Date
    Oct 2009
    Posts
    4,326
    I have bad news for you. QPushButton doesn't have SetIcon method:
    http://doc.trolltech.com/4.6/qpushbutton.html
    Do you want to show us your code snippet how do you load pixmaps, create icons and set them to the buttons?

  5. #5
    Registered User iftifn's Avatar
    Join Date
    Jan 2010
    Posts
    15
    Quote Originally Posted by divanov View Post
    I have bad news for you. QPushButton doesn't have SetIcon method:
    http://doc.trolltech.com/4.6/qpushbutton.html
    Do you want to show us your code snippet how do you load pixmaps, create icons and set them to the buttons?
    And this is said by forum expert.. Have you forgotten about inheritance? QPushButton inherits ::setIcon() method.

    The way to have any number of icons for a button or any control:
    Write custom SLOTS: write custom slot, which will do the standart slot action + will change the icon with ->setIcon() method.

    Example:
    connect(myPushButton, SIGNALS(clicked()), classForSlots, SLOTS(on_myPushButton_clicked));

    void on_myPushButton_clicked()
    {
    myPushButton->setIcon(icon);
    <some code for app logic>
    }

    Just choose the right signal, or even write your own new signal.

  6. #6
    Nokia Developer Champion danhicksbyron's Avatar
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209
    Or you can do pretty much the same thing through style sheets (not set icon, but set background or border):

    DataEntryWidget QPushButton#upButton {
    margin: 0px;
    border-width: 8px;
    border-image: url(:/DataEntryWidget/images/button_big_blank_normal.png) 8 8 8 8;
    }
    DataEntryWidget QPushButton#upButton:pressed {
    margin: 0px;
    border-width: 8px;
    border-image: url(:/DataEntryWidget/images/button_big_blank_selected.png) 8 8 8 8;
    }
    Last edited by danhicksbyron; 2010-02-05 at 01:52.

  7. #7
    Nokia Developer Moderator divanov's Avatar
    Join Date
    Oct 2009
    Posts
    4,326
    Quote Originally Posted by danhicksbyron View Post
    Or you can do pretty much the same thing through style sheets (not set icon, but set background or border)
    Yes, I also have a feeling that question is about styling QPushButton. But still not sure. Do not forget about "enabled" and "disabled" pseudo-states.
    Last edited by divanov; 2010-02-05 at 09:20. Reason: fixing typos

  8. #8
    Nokia Developer Champion danhicksbyron's Avatar
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209
    There's enough for everyone:

    http://doc.qt.nokia.com/4.6-snapshot...-pseudo-states

    checked/unchecked, disabled/enabled, pressed, focused, and many more.

Similar Threads

  1. Style sheets are driving me crazy
    By danhicksbyron in forum Qt
    Replies: 7
    Last Post: 2010-01-24, 05:31
  2. Error in QT Documentation
    By tamhanna in forum [Archived] Qt SDKs and Tools
    Replies: 8
    Last Post: 2010-01-22, 13:55

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved