Results 1 to 10 of 10

Thread: Icon only button

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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).

  2. #2
    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

  3. #3
    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

  4. #4
    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?

  5. #5
    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
  •  
Qt is a trademark of The Qt Company.