PDA

View Full Version : QToolButton will not display its icon



JimBrown
8th March 2007, 23:05
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:


QToolButton* myToolButton;
QWidget* layoutWidget;
QHBoxLayout* hboxLayout;

myToolButton = new QToolButton(layoutWidget);
myToolButton->setObjectName(QString::fromUtf8("myToolButton"));
myToolButton->setIcon(QIcon(QString::fromUtf8("images/icon_xpm")));
myToolButton->setCheckable(true);

hboxLayout->addWidget(myToolButton);

myToolButton->setToolTip("...");
myToolButton->setText(QString("..."));

editModeButtonGroup_->addButton(myToolButton, 0);


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

JimBrown
8th March 2007, 23:13
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.

jacek
8th March 2007, 23:32
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).

wysota
9th March 2007, 00:59
First, I want to thank the Qt Forum community for providing this great service. Many, many thanks.

QtForum (http://www.qtforum.org) or QtCentre forum (http://www.qtcentre.org/forum)? :)

JimBrown
9th March 2007, 02:19
QtForum (http://www.qtforum.org) or QtCentre forum (http://www.qtcentre.org/forum)? :)

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!

JimBrown
9th March 2007, 14:27
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.

jacek
9th March 2007, 18:54
The icon is stored in resources.
Are you sure? Could you post your .qrc file?