Results 1 to 7 of 7

Thread: QToolButton will not display its icon

  1. #1
    Join Date
    Feb 2007
    Posts
    31
    Thanks
    11

    Default QToolButton will not display its icon

    Hello,

    First, I want to thank the Qt Forum community for providing this great service. Many, many thanks.

    My latest problem with a port from Qt 3 to Qt 4 is a QToolButton will not display its icon.
    This was working code in Qt 3:

    Qt Code:
    1. QToolButton* myToolButton;
    2. QWidget* layoutWidget;
    3. QHBoxLayout* hboxLayout;
    4.  
    5. myToolButton = new QToolButton(layoutWidget);
    6. myToolButton->setObjectName(QString::fromUtf8("myToolButton"));
    7. myToolButton->setIcon(QIcon(QString::fromUtf8("images/icon_xpm")));
    8. myToolButton->setCheckable(true);
    9.  
    10. hboxLayout->addWidget(myToolButton);
    11.  
    12. myToolButton->setToolTip("...");
    13. myToolButton->setText(QString("..."));
    14.  
    15. editModeButtonGroup_->addButton(myToolButton, 0);
    To copy to clipboard, switch view to plain text mode 


    The dialog box displays and the buttons function, but they don't display their icon image. Any insight as to what's wrong?

    Thanks again,
    Jim Brown
    Last edited by wysota; 9th March 2007 at 00:58. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2007
    Posts
    31
    Thanks
    11

    Default Re: QToolButton will not display its icon

    By the way, the icons display just fine in Qt Designer. And the icon files are listed in the application.qrc file in case that helps.

  3. #3
    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: QToolButton will not display its icon

    Quote Originally Posted by JimBrown View Post
    myToolButton->setIcon(QIcon(QString::fromUtf8("images/icon_xpm")));
    If that icon is stored in resources, try ":/images/icon_xpm", otherwise use an absolute path (QCoreApplication::applicationDirPath() might be useful).

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

    JimBrown (9th March 2007)

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QToolButton will not display its icon

    Quote Originally Posted by JimBrown View Post
    First, I want to thank the Qt Forum community for providing this great service. Many, many thanks.
    QtForum or QtCentre forum?

  6. #5
    Join Date
    Feb 2007
    Posts
    31
    Thanks
    11

    Default Re: QToolButton will not display its icon

    Quote Originally Posted by wysota View Post
    QtCentre forum! You and jacek are great! You know, it's funny - I'm at home now, and I always log in to QtCentre forum from work, so I did a Google search to try to find the URL, and I just came across "QtForum" for the first time. It looks very similar to this site, but you guys have really helped me out, so my gratitude is definitely going to you and QtCentre forum!

    I'll try jacek's tip when I get in to work tomorrow morning.

    Thanks, guys!

  7. #6
    Join Date
    Feb 2007
    Posts
    31
    Thanks
    11

    Default Re: QToolButton will not display its icon

    Quote Originally Posted by jacek View Post
    If that icon is stored in resources, try ":/images/icon_xpm", otherwise use an absolute path (QCoreApplication::applicationDirPath() might be useful).
    The icon is stored in resources.

    I needed to use the absolute path. I find this a little odd - the file containing the line
    myToolButton->setIcon(QIcon(QString::fromUtf8("images/icon_xpm")));
    was generated from the dialog.ui file from Designer, and Designer displayed the icons with no problem. So Qt's own auto-generated code didn't work?

    I find this odd, too: I have menus in this app created from QActions, and the statement
    viewZoomOutAction = new QAction(QIcon(":/images/zoomout.png"),"Zoom &Out", this);
    works fine with the ":/images/filename" string. Why didn't this work for the QToolButton:
    myToolButton->setIcon(QIcon(QString::fromUtf8(":/images/icon_xpm"))); ?

    Thanks again, guys.

  8. #7
    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: QToolButton will not display its icon

    Quote Originally Posted by JimBrown View Post
    The icon is stored in resources.
    Are you sure? Could you post your .qrc file?

Similar Threads

  1. Replies: 8
    Last Post: 18th March 2011, 11:27
  2. QSystemTrayIcon doesn't show icon ?
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 25th January 2007, 19:17
  3. Problem with qtoolbutton
    By moowy in forum Qt Programming
    Replies: 1
    Last Post: 22nd September 2006, 13:30
  4. Displaying Icon
    By Seema Rao in forum Qt Programming
    Replies: 4
    Last Post: 9th February 2006, 20:43
  5. How to dispay an icon in the first column of QTreeView
    By yogeshm02 in forum Qt Programming
    Replies: 1
    Last Post: 5th January 2006, 15:51

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.