PDA

View Full Version : Icons dont apear in tolbar



john_god
19th August 2008, 18:30
Hi. I'm a newby migration to Qt 4 from MS Visual C++ 6.
I create a basic Window in Designer, with menu and toolbar with actions and icons, but the icons dont show. I create the qrc file and use Q_INIT_RESOURCE.

What could be wrong?

HELP!!!!!

my code is:


#include <QApplication>
#include <QMainWindow>
#include "ui_janela.h"

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

Q_INIT_RESOURCE(images);
QApplication app(argc, argv);

Ui_mainWindow ui;

QMainWindow *ja = new QMainWindow;

ui.setupUi(ja);

ja->show();

return app.exec();
}

spirit
19th August 2008, 18:34
did you add resource declaration to .pro file?


RESOURCES += resource_file_name.qrc

john_god
19th August 2008, 18:47
yes i did

jacek
19th August 2008, 18:47
What is your icons format?

john_god
19th August 2008, 18:56
they are .png. Ive copied the images from the tutorials of the oficial qt 4 porgramming book

I've also tried the example of the MDI, without the designer, i've added a new icon to the toolbar, new action, new code to that specific tolbar botton and worked with .png and .ico, but with the designer it doesnt work

spirit
19th August 2008, 19:15
can you show your pro-file?

john_god
19th August 2008, 19:17
################################################## ####################
# Automatically generated by qmake (2.01a) dom 17. Ago 22:33:02 2008
################################################## ####################

TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .

# Input
FORMS += janela.ui
SOURCES += janela.cpp
RESOURCES += images.qrc

john_god
19th August 2008, 19:19
the image.qrc files is:


<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>images/copy.png</file>
<file>images/cut.png</file>
<file>images/new.png</file>
<file>images/open.png</file>
<file>images/paste.png</file>
<file>images/save.png</file>

</qresource>
</RCC>

spirit
19th August 2008, 19:24
I think problem in ui file.
did ui file contain lines like these


....
<iconset resource="test.qrc" >
...
<resources>
<include location="test.qrc" />
</resources>
...

?

john_god
19th August 2008, 19:33
If the problem is with this file i think thats not editable because its create by the designer
am i right ? But where it goes:


/************************************************** ******************************
** Form generated from reading ui file 'janela.ui'
**
** Created: Sun 17. Aug 22:33:08 2008
** by: Qt User Interface Compiler version 4.4.1
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
************************************************** ******************************/

#ifndef UI_JANELA_H
#define UI_JANELA_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QMainWindow>
#include <QtGui/QMenu>
#include <QtGui/QMenuBar>
#include <QtGui/QStatusBar>
#include <QtGui/QToolBar>
#include <QtGui/QWidget>

QT_BEGIN_NAMESPACE

class Ui_mainWindow
{
public:
QAction *actionNovo;
QAction *actionAbrir;
QAction *actionSobre;
QAction *actionGuardar;
QAction *actionGuardar_Como;
QWidget *centralwidget;
QMenuBar *menubar;
QMenu *menuSobre;
QMenu *menuFile;
QStatusBar *statusbar;
QToolBar *toolBar;

void setupUi(QMainWindow *mainWindow)
{
if (mainWindow->objectName().isEmpty())
mainWindow->setObjectName(QString::fromUtf8("mainWindow"));
mainWindow->resize(438, 418);
QIcon icon;
icon.addPixmap(QPixmap(QString::fromUtf8("../../../../Documents and Settings/Joao/.designer/backup/images/icon.png")), QIcon::Normal, QIcon::Off);
mainWindow->setWindowIcon(icon);
actionNovo = new QAction(mainWindow);
actionNovo->setObjectName(QString::fromUtf8("actionNovo"));
QIcon icon1;
icon1.addPixmap(QPixmap(QString::fromUtf8("images/new.png")), QIcon::Normal, QIcon::Off);
actionNovo->setIcon(icon1);
actionAbrir = new QAction(mainWindow);
actionAbrir->setObjectName(QString::fromUtf8("actionAbrir"));
QIcon icon2;
icon2.addPixmap(QPixmap(QString::fromUtf8("images/open.png")), QIcon::Normal, QIcon::Off);
actionAbrir->setIcon(icon2);
actionSobre = new QAction(mainWindow);
actionSobre->setObjectName(QString::fromUtf8("actionSobre"));
actionGuardar = new QAction(mainWindow);
actionGuardar->setObjectName(QString::fromUtf8("actionGuardar"));
QIcon icon3;
icon3.addPixmap(QPixmap(QString::fromUtf8("images/save.png")), QIcon::Normal, QIcon::Off);
actionGuardar->setIcon(icon3);
actionGuardar_Como = new QAction(mainWindow);
actionGuardar_Como->setObjectName(QString::fromUtf8("actionGuardar_Como"));
centralwidget = new QWidget(mainWindow);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
mainWindow->setCentralWidget(centralwidget);
menubar = new QMenuBar(mainWindow);
menubar->setObjectName(QString::fromUtf8("menubar"));
menubar->setGeometry(QRect(0, 0, 438, 21));
menuSobre = new QMenu(menubar);
menuSobre->setObjectName(QString::fromUtf8("menuSobre"));
menuFile = new QMenu(menubar);
menuFile->setObjectName(QString::fromUtf8("menuFile"));
mainWindow->setMenuBar(menubar);
statusbar = new QStatusBar(mainWindow);
statusbar->setObjectName(QString::fromUtf8("statusbar"));
mainWindow->setStatusBar(statusbar);
toolBar = new QToolBar(mainWindow);
toolBar->setObjectName(QString::fromUtf8("toolBar"));
mainWindow->addToolBar(Qt::TopToolBarArea, toolBar);

menubar->addAction(menuFile->menuAction());
menubar->addAction(menuSobre->menuAction());
menuSobre->addAction(actionSobre);
menuFile->addAction(actionNovo);
menuFile->addAction(actionAbrir);
menuFile->addAction(actionGuardar);
menuFile->addAction(actionGuardar_Como);
toolBar->addAction(actionNovo);
toolBar->addAction(actionAbrir);
toolBar->addAction(actionGuardar);

retranslateUi(mainWindow);

QMetaObject::connectSlotsByName(mainWindow);
} // setupUi

void retranslateUi(QMainWindow *mainWindow)
{
mainWindow->setWindowTitle(QApplication::translate("mainWindow", "Janela", 0, QApplication::UnicodeUTF8));

#ifndef QT_NO_TOOLTIP
mainWindow->setToolTip(QApplication::translate("mainWindow", "Janela", 0, QApplication::UnicodeUTF8));
#endif // QT_NO_TOOLTIP


#ifndef QT_NO_STATUSTIP
mainWindow->setStatusTip(QApplication::translate("mainWindow", "status janela", 0, QApplication::UnicodeUTF8));
#endif // QT_NO_STATUSTIP

actionNovo->setText(QApplication::translate("mainWindow", "Novo", 0, QApplication::UnicodeUTF8));
actionAbrir->setText(QApplication::translate("mainWindow", "Abrir", 0, QApplication::UnicodeUTF8));
actionSobre->setText(QApplication::translate("mainWindow", "Sobre", 0, QApplication::UnicodeUTF8));
actionGuardar->setText(QApplication::translate("mainWindow", "Guardar", 0, QApplication::UnicodeUTF8));
actionGuardar_Como->setText(QApplication::translate("mainWindow", "Guardar Como", 0, QApplication::UnicodeUTF8));
menuSobre->setTitle(QApplication::translate("mainWindow", "Sobre", 0, QApplication::UnicodeUTF8));
menuFile->setTitle(QApplication::translate("mainWindow", "File", 0, QApplication::UnicodeUTF8));
toolBar->setWindowTitle(QApplication::translate("mainWindow", "toolBar", 0, QApplication::UnicodeUTF8));

#ifndef QT_NO_STATUSTIP
toolBar->setStatusTip(QApplication::translate("mainWindow", "status janela", 0, QApplication::UnicodeUTF8));
#endif // QT_NO_STATUSTIP

} // retranslateUi

};

namespace Ui {
class mainWindow: public Ui_mainWindow {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_JANELA_H

spirit
19th August 2008, 19:38
try this example.

john_god
19th August 2008, 19:49
Thank a lot spirit that works . I gonna studdy the two ui files, to see the diferences.

But I steel dont know what i am doing wrong

john_god
20th August 2008, 01:12
I 've delete all icons and action in the designer, and then add all again. It works fine now.
Thank you all for the help