Results 1 to 10 of 10

Thread: Icon only button

  1. #1
    Join Date
    Jan 2007
    Posts
    91
    Thanks
    21
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Icon only button

    I want a series of buttons <>^V (left, right, up, down). How do I create a button with only an icon/image, on it? When I use the QPushButton(icon, text) constructor all I get is the text.
    - Bruce

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Icon only button

    One possibility is to use QToolButton and it's built-in arrow type property.
    J-P Nurmi

  3. #3
    Join Date
    Jan 2007
    Posts
    91
    Thanks
    21
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Icon only button

    I was attempting to use a 'gif" file. Once I converted it to a jpg file, it worked. I even gave the "gif" as the file type. The problem is, the file type for the load() API is not well documented. I couldn't tell what valid formats are handled on Windows and which are not. Anyway, once I converted the gifs to jpgs, it seems to work.

    Thanks for your help.
    - Bruce

  4. #4
    Join Date
    Jan 2007
    Posts
    91
    Thanks
    21
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Smile Re: Icon only button

    I will also consider using the QToolButton as well in the future.

    Again, thanks for your help
    - Bruce

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Icon only button

    Quote Originally Posted by bruccutler View Post
    The problem is, the file type for the load() API is not well documented. I couldn't tell what valid formats are handled on Windows and which are not.
    I guess you have just missed the "See also Reading and Writing Image Files." part of the docs.
    Last edited by jacek; 19th January 2007 at 19:16. Reason: typo

  6. The following user says thank you to jacek for this useful post:

    bruccutler (19th January 2007)

  7. #6
    Join Date
    Jan 2007
    Posts
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Icon only button

    Are you sure the QIcon you pass in QPushButton has its image loaded? The following code should work:

    Qt Code:
    1. #include <QApplication>
    2. #include <QPushButton>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7. QPushButton *pushButton = new QPushButton(QIcon("path_to_your_icon"), "text", 0);
    8. pushButton->show();
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    Please check that the path to the icon is valid (or better use the resource system of Qt). Next you may try it without the text and set the QPushButton's flat-property to true (might look better with icon-only buttons).

  8. #7
    Join Date
    Jan 2007
    Posts
    91
    Thanks
    21
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Icon only button

    I still would like to know why it failed to load the .gif file when it succeeded with the .jpg. But for now, I'm moving on.

    Thanks for all the help.
    - Bruce

  9. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Icon only button

    Qt doesn't support GIF by default, due to licensing issues. You have to recompile Qt with GIF support turned on. See "configure -help" for details.
    J-P Nurmi

  10. #9
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Icon only button

    I never am able to do this:
    I did what the previous poster said,
    [qtcode]
    #include <QApplication>
    #include <QPushButton>
    int main(int argc, char *argv[])
    {

    QApplication app(argc, argv);
    QPushButton *pushButton = new QPushButton(QIcon("TestQT.ico"), "text", 0);
    pushButton->show();
    return app.exec();

    }

    [/qtcode]

    However, even though TestQT.ico and this program are in same folder, it does not work... neither does C:/blabla.... What do I do?

  11. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Icon only button

    ICO is neither a supported format. It is available as a commercial solution, though. As far as I remember, there is some open source implementation out there as well.

    You can simply use supported image formats, like PNG for constructing a QIcon.
    Use the QImageReader::supportedImageFormats() and QImageWriter::supportedImageFormats() functions to retrieve a complete list of the supported file formats.
    J-P Nurmi

Similar Threads

  1. set Icon to .app file
    By vishal.chauhan in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2007, 21:13
  2. Mouse Over event on button
    By vishal.chauhan in forum Qt Programming
    Replies: 9
    Last Post: 10th January 2007, 05:03
  3. QPushbutton Flat property and icon appearance.
    By darpan in forum Qt Programming
    Replies: 1
    Last Post: 4th November 2006, 08:30
  4. Push button double click
    By curtisw in forum Qt Programming
    Replies: 3
    Last Post: 15th February 2006, 16:40
  5. Displaying Icon
    By Seema Rao in forum Qt Programming
    Replies: 4
    Last Post: 9th February 2006, 20:43

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.