×

Discussion Board

Results 1 to 15 of 15
  1. #1
    Regular Contributor
    Join Date
    Nov 2011
    Posts
    104

    How to set button images for Qt?

    Hi all,
    Now i am trying to set images for QPushbutton which means button images for my application.

    Can anyone help me with this?I dont know whether to bring the image using UI design or else through the code.


    Regards,
    Harish

  2. #2
    Nokia Developer Champion
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: How to set button images for Qt?

    check QPushButton::setIcon().

  3. #3
    Regular Contributor
    Join Date
    Nov 2011
    Posts
    104

    Re: How to set button images for Qt?

    Hi savaj,
    Here is my code:

    #include "mainwindow.h"

    #include <QtGui/QApplication>
    #include<QPushButton>
    #include<QIcon>




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

    QPushButton *button = new QPushButton ();

    button->setIcon(QIcon("favicon.Icon"));

    button->show();



    return app.exec();
    }
    I was not able to get my image displayed in the button could you point out me where i went wrong?


    Regards,
    Harish.

  4. #4
    Nokia Developer Champion
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: How to set button images for Qt?

    What is location of your "favicon.Icon" icon.

    Instead you create simple application and create button in mainwindow.cpp, so that it is easily visible to you.

  5. #5
    Regular Contributor
    Join Date
    Nov 2011
    Posts
    104

    Re: How to set button images for Qt?

    Location of "favicon.icon" Icon was in C drive and i had added it to my coding but still not getting the image

  6. #6
    Regular Contributor
    Join Date
    Nov 2011
    Posts
    104

    Re: How to set button images for Qt?

    Is it possible to add a button image with a QPixmap?I had tried with that too...

    Here is my code:

    #include "mainwindow.h"

    #include <QtGui/QApplication>
    #include<QPushButton>
    #include<QIcon>
    #include<QPixmap>




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

    QPushButton *button = new QPushButton ();



    QPixmap pixmap("C:\QtSDK\Examples\4.7\test\favicon.Icon");
    QIcon ButtonIcon(pixmap);
    button->setIcon(ButtonIcon);
    button->setIconSize(pixmap.rect().size());
    button->show();


    return app.exec();
    }

    Here too i was not getting the image in the button what might be the error?

  7. #7
    Regular Contributor
    Join Date
    Nov 2011
    Posts
    104

    Re: How to set button images for Qt?

    Hi savaj,
    I got the image displayed in the button but what i need is to display the image over the button which means i dont need to see the button the image should cover the button.Is that possible?

    Whether i have to resize the image or what to do?

  8. #8
    Nokia Developer Champion
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: How to set button images for Qt?

    Image is of what type? .icon?? You should use supported image type.

    And in path use "C:/QtSDK/Examples/4.7/test/favicon.Icon" instead.

  9. #9
    Nokia Developer Champion
    Join Date
    Sep 2007
    Location
    Bhavnagar
    Posts
    928

    Re: How to set button images for Qt?

    You can resize the image or select the image of large size.
    Jajal Mehul

  10. #10
    Nokia Developer Champion
    Join Date
    Sep 2007
    Location
    Bhavnagar
    Posts
    928

    Re: How to set button images for Qt?

    Hi,

    Check this link for customizing the button in Qt.

    http://qt-articles.blogspot.com/2010...ton-in-qt.html
    Jajal Mehul

  11. #11
    Regular Contributor
    Join Date
    Nov 2011
    Posts
    104

    Re: How to set button images for Qt?

    I am using .ico as well as .png image......i had declared the path where the image is found.
    but still image is of small size is there any way to resize the image through coding?

  12. #12
    Regular Contributor
    Join Date
    Nov 2011
    Posts
    104

    Re: How to set button images for Qt?

    Is there anyway to resize the image through coding?

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

    Re: How to set button images for Qt?


  14. #14
    Nokia Developer Champion
    Join Date
    Sep 2007
    Location
    Bhavnagar
    Posts
    928

    Re: How to set button images for Qt?

    Quote Originally Posted by mkhpad View Post
    Is there anyway to resize the image through coding?
    Here is sample example for resize the image..

    http://www.developer.nokia.com/Commu...ication/widget
    Jajal Mehul

  15. #15
    Regular Contributor
    Join Date
    Nov 2011
    Posts
    104

    Re: How to set button images for Qt?

    Thank You for your help

Similar Threads

  1. use Call Button( Green key) and End Button (Red key) in my VOIP Application
    By nishadamit09@gmail.com in forum Symbian User Interface
    Replies: 12
    Last Post: 2011-10-04, 07:30
  2. Two images no one button
    By Northers666 in forum Qt
    Replies: 2
    Last Post: 2010-07-08, 16:29
  3. Detroy app when user press hang up button (red button)
    By ammanage in forum Mobile Java General
    Replies: 9
    Last Post: 2009-09-21, 19:29
  4. How to make Play / Stop button and Record button
    By Kaz32 in forum Symbian User Interface
    Replies: 1
    Last Post: 2009-04-24, 05:13

Posting Permissions

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