lerwys
27th April 2009, 12:10
Hi all,
I would like to subclass QMainWindow in order to create a simple application: displyaing an image.
Why does my code not show the spider3.jpg image ?
NOTE: I have already made the .qrc file and pointed to the corrected image path
NOTE 2: newGame() is not yet implemented
.h file
#ifndef FREECELL_H
#define FREECELL_H
#include <QMainWindow>
class QWidget;
class QGraphicsScene;
class QGraphicsView;
class QGraphicsPixmapItem;
class FreeCell : public QMainWindow
{
Q_OBJECT
public:
FreeCell();
protected:
void closeEvent(QCloseEvent *event);
private slots:
void newGame();
private:
void createActions();
void createMenus();
void createCentral();
QAction *newGameAction;
QAction *exitAction;
QAction *aboutAction;
QMenu *fileMenu;
QMenu *helpMenu;
QGraphicsScene *centralScene;
QGraphicsView *centralView;
};
#endif // FREECELL_H
.cpp
#include "freecell.h"
#include <QtGui>
FreeCell::FreeCell()
{
createActions();
createMenus();
createCentral();
}
void FreeCell::closeEvent(QCloseEvent *event)
{
int cod = QMessageBox::warning(this, tr("FreeCell"),
tr("Você tem certeza que deseja sair?"),
QMessageBox::Yes, QMessageBox::No | QMessageBox::Default);
if( cod == QMessageBox::Yes )
event->accept();
else
event->ignore();
}
void FreeCell::createActions()
{
newGameAction = new QAction(tr("&Novo Jogo"), this);
newGameAction->setShortcut(tr("Ctrl + N"));
newGameAction->setStatusTip(tr("Inicia uma nova partida"));
connect(newGameAction, SIGNAL(triggered()), this, SLOT(newGame()));
exitAction = new QAction(tr("&Sair"), this);
exitAction->setStatusTip(tr("Fecha o jogo"));
connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
aboutAction = new QAction(tr("&Sobre"), this);
aboutAction->setStatusTip(tr("Informaçoes sobre o programa"));
connect(aboutAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
}
void FreeCell::createMenus()
{
fileMenu = menuBar()->addMenu(tr("Arquivo"));
fileMenu->addAction(newGameAction);
fileMenu->addSeparator();
fileMenu->addAction(exitAction);
helpMenu = menuBar()->addMenu(tr("Ajuda"));
helpMenu->addAction(aboutAction);
}
void FreeCell::createCentral()
{
centralScene = new QGraphicsScene(this);
centralView = new QGraphicsView;
//adição de todas as widgets e outros
centralScene->addPixmap(QPixmap(":/images/spider3.jpg"));
centralScene->setBackgroundBrush(Qt::darkGreen);
centralScene->update(centralScene->sceneRect());
centralView->setScene(centralScene);
setCentralWidget(centralView);
centralView->show();
}
void FreeCell::newGame()
{
}
main
#include "freecell.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
FreeCell *game = new FreeCell;
game->show();
return app.exec();
}
.qrc code
<RCC>
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>images/solidSnake.jpg</file>
<file>images/spider3.jpg</file>
</qresource>
</RCC>
Thanks in advance
I would like to subclass QMainWindow in order to create a simple application: displyaing an image.
Why does my code not show the spider3.jpg image ?
NOTE: I have already made the .qrc file and pointed to the corrected image path
NOTE 2: newGame() is not yet implemented
.h file
#ifndef FREECELL_H
#define FREECELL_H
#include <QMainWindow>
class QWidget;
class QGraphicsScene;
class QGraphicsView;
class QGraphicsPixmapItem;
class FreeCell : public QMainWindow
{
Q_OBJECT
public:
FreeCell();
protected:
void closeEvent(QCloseEvent *event);
private slots:
void newGame();
private:
void createActions();
void createMenus();
void createCentral();
QAction *newGameAction;
QAction *exitAction;
QAction *aboutAction;
QMenu *fileMenu;
QMenu *helpMenu;
QGraphicsScene *centralScene;
QGraphicsView *centralView;
};
#endif // FREECELL_H
.cpp
#include "freecell.h"
#include <QtGui>
FreeCell::FreeCell()
{
createActions();
createMenus();
createCentral();
}
void FreeCell::closeEvent(QCloseEvent *event)
{
int cod = QMessageBox::warning(this, tr("FreeCell"),
tr("Você tem certeza que deseja sair?"),
QMessageBox::Yes, QMessageBox::No | QMessageBox::Default);
if( cod == QMessageBox::Yes )
event->accept();
else
event->ignore();
}
void FreeCell::createActions()
{
newGameAction = new QAction(tr("&Novo Jogo"), this);
newGameAction->setShortcut(tr("Ctrl + N"));
newGameAction->setStatusTip(tr("Inicia uma nova partida"));
connect(newGameAction, SIGNAL(triggered()), this, SLOT(newGame()));
exitAction = new QAction(tr("&Sair"), this);
exitAction->setStatusTip(tr("Fecha o jogo"));
connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
aboutAction = new QAction(tr("&Sobre"), this);
aboutAction->setStatusTip(tr("Informaçoes sobre o programa"));
connect(aboutAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
}
void FreeCell::createMenus()
{
fileMenu = menuBar()->addMenu(tr("Arquivo"));
fileMenu->addAction(newGameAction);
fileMenu->addSeparator();
fileMenu->addAction(exitAction);
helpMenu = menuBar()->addMenu(tr("Ajuda"));
helpMenu->addAction(aboutAction);
}
void FreeCell::createCentral()
{
centralScene = new QGraphicsScene(this);
centralView = new QGraphicsView;
//adição de todas as widgets e outros
centralScene->addPixmap(QPixmap(":/images/spider3.jpg"));
centralScene->setBackgroundBrush(Qt::darkGreen);
centralScene->update(centralScene->sceneRect());
centralView->setScene(centralScene);
setCentralWidget(centralView);
centralView->show();
}
void FreeCell::newGame()
{
}
main
#include "freecell.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
FreeCell *game = new FreeCell;
game->show();
return app.exec();
}
.qrc code
<RCC>
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>images/solidSnake.jpg</file>
<file>images/spider3.jpg</file>
</qresource>
</RCC>
Thanks in advance