×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Regular Contributor
    Join Date
    Nov 2011
    Location
    Coimbatore
    Posts
    87

    Post How to add two images in Pushbutton using CSS QT?

    Hi All,
    I am in need of adding two images to the pushbutton!!!
    The first image must be default and the second image should become active when clicked or pressed, it should be overcoming or overlapping the first image or so..
    I have tried this code but its not working properly!!!

    from this url:
    http://wiki.maemo.org/Customising_Qt...urs_and_Images

    QPushButton{background-image: url(:/images/activity.png);}
    QPushButton:pressed{background-image: url(:/images/activity_active.png);}

    What should i give instead of pressed and that might appear when clicked or touched

    Anyone please help me in sorting this mistake made by me???

    Thanks in Advance & Regards,
    Naufal.A
    Last edited by naufalahad; 2011-12-12 at 08:54. Reason: mistake

  2. #2
    Nokia Developer Expert
    Join Date
    Feb 2008
    Posts
    183

    Re: How to add two images in Pushbutton using CSS QT?

    Can you share the whole code you are trying to use?

    For me this works (yeah its colors instead of images):
    Code:
        QString buttonStyle(
        "QPushButton {color: rgb(255,0,0);\n"
                "background-color: rgb(0, 255, 0);\n"
                "border-bottom: 1px solid rgb(33,33,33);\n"
                "border-right: 1px solid rgb(33,33,33);\n"
                "border-top: 1px solid rgb(220,220,220);\n"
                "border-left: 1px solid rgb(220,220,220);\n"
                "border-radius: 3px;\n"
                "font-weight: normal;\n"
                "font-size: 16px; } \n"
        "QPushButton:pressed {background-color: rgb(75, 75, 75);\n"
                "border-top: 1px solid rgb(33,33,33);\n"
                "border-left: 1px solid rgb(33,33,33);\n"
                "border-bottom: 1px solid rgb(220,220,220);\n"
                "border-right: 1px solid rgb(220,220,220); }\n");
    
        QPushButton *testBtn = new QPushButton("Click me", this);
        testBtn->resize(QSize(100, 30));
        testBtn->setStyleSheet(buttonStyle);

  3. #3
    Regular Contributor
    Join Date
    Nov 2011
    Location
    Coimbatore
    Posts
    87

    Re: How to add two images in Pushbutton using CSS QT?

    Hi Fuzzbender,
    But when i use "pressed" option it is for that pressing time alone the image changes,but i need to change the image and display them until another button is pressed. Consider i am having two buttons with default images in them .. when i press the second button the second button must change the image and should be active till the another button is pressed!!! could you get me ???what i am trying to say??

  4. #4
    Nokia Developer Expert
    Join Date
    Feb 2008
    Posts
    183

    Re: How to add two images in Pushbutton using CSS QT?

    You want your button1 to remain pressed down, until button2 is pressed? And vice versa?

    If I understood correctly your wants and needs, check properties checkable and checked for the QPushButton.

    Add checkable = true; and checked = true; to button1 (and checkable = true; checked = false; to button2) and switch the checked variable values when
    a button that is "up" (i.e. not pressed down ('checked')) is pressed. Is this what you need?

  5. #5
    Nokia Developer Expert
    Join Date
    Feb 2008
    Posts
    183

    Re: How to add two images in Pushbutton using CSS QT?

    Or if you just need to switch the icon of the button when it has been pressed, see the QPushButton::setIcon() API.

  6. #6
    Regular Contributor
    Join Date
    Nov 2011
    Location
    Coimbatore
    Posts
    87

    Re: How to add two images in Pushbutton using CSS QT?

    Hi Fuzzbender,
    I think you are right!!!!I will check it out and tell you .,
    Thanks for your reply.,.,

    Regards,
    Naufal.A

  7. #7
    Regular Contributor
    Join Date
    Nov 2011
    Location
    Coimbatore
    Posts
    87

    Re: How to add two images in Pushbutton using CSS QT?

    Hi Fuzzbender,
    I tried the properties which you had given,.,. but there is no change when i press the other buttton.. the image remains the same and did not change at all...
    Now i will check for the API which you said,..
    Regards and Thanks,
    Naufal.A

  8. #8
    Nokia Developer Expert
    Join Date
    Feb 2008
    Posts
    183

    Re: How to add two images in Pushbutton using CSS QT?

    You'll need to have some logic what happens when a button is pressed (i.e. clicked() signal needs to be connected to custom slot), otherwise it won't work.

  9. #9
    Regular Contributor
    Join Date
    Nov 2011
    Location
    Coimbatore
    Posts
    87

    Re: How to add two images in Pushbutton using CSS QT?

    Hi fuzzbender,
    I will just checkout with the code for all the buttons and let you know that it works or not!!!

    Thanks and Regards,
    Naufal.A

Similar Threads

  1. Replies: 4
    Last Post: 2011-10-30, 11:09
  2. problem getting the images from images.google.com..!!!
    By buffon2009 in forum Mobile Java General
    Replies: 1
    Last Post: 2011-01-19, 01:43
  3. Can not show the icon on a PushButton???
    By zuii in forum [Archived] Qt SDKs and Tools
    Replies: 2
    Last Post: 2009-12-31, 16:11
  4. Replies: 5
    Last Post: 2009-03-09, 08:24

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×