To anda_skoa and d_stranz --
To anda_skoa:
Unfortunately, it doesn't seem to have worked when extended to the entire chess board.
Here's an abbreviated sample to show what's happening.
First, a successful test without the vector:
// ChessTest2
// MDJ 2016/11/02
// Qt 5.7 - Qt Creator 4.0.2 - Qt Widgets Application
// No changes to files other than this main.cpp - except:
// Added line "RESOURCES += application.qrc" to ChessTest2.pro.
// Added images folder with files:
// blackSquare.png
// whiteSquare.png
// Added application.qrc Resources file:
// <!DOCTYPE RCC><RCC version="1.0">
// <qresource>
// <file>images/blackSquare.png</file>
// <file>images/whiteSquare.png</file>
// </qresource>
// </RCC>
// This test compiles:
// and runs as expected, displaying a "black" square
// and a "white" square in the lower left corner
// of the view.
#include "mainwindow.h"
#include <QApplication>
#include <QPixmap>
#include <QGraphicsPixmapItem>
#include <QGraphicsScene>
#include <QGraphicsView>
int main( int argc, char **argv )
{
// Load the Resource Graphics
// Establish the Scene
scene.setSceneRect( -370.0, -370.0, 740.0, 740.0 );
// Set up the Board
pixmapItem0.setPixmap( pixmapBlackSquare );
pixmapItem0.setPos( -370, 296 );
scene.addItem( &pixmapItem0 );
pixmapItem1.setPixmap( pixmapWhiteSquare );
pixmapItem1.setPos( -296, 296 );
scene.addItem( &pixmapItem1 );
// Establish the View
view.setGeometry( 400, 200, 760, 760 );
view.
setRenderHints( QPainter::Antialiasing );
view.show();
return app.exec();
}
// ChessTest2
// MDJ 2016/11/02
// Qt 5.7 - Qt Creator 4.0.2 - Qt Widgets Application
// No changes to files other than this main.cpp - except:
// Added line "RESOURCES += application.qrc" to ChessTest2.pro.
// Added images folder with files:
// blackSquare.png
// whiteSquare.png
// Added application.qrc Resources file:
// <!DOCTYPE RCC><RCC version="1.0">
// <qresource>
// <file>images/blackSquare.png</file>
// <file>images/whiteSquare.png</file>
// </qresource>
// </RCC>
// This test compiles:
// and runs as expected, displaying a "black" square
// and a "white" square in the lower left corner
// of the view.
#include "mainwindow.h"
#include <QApplication>
#include <QPixmap>
#include <QGraphicsPixmapItem>
#include <QGraphicsScene>
#include <QGraphicsView>
int main( int argc, char **argv )
{
QApplication app(argc, argv);
// Load the Resource Graphics
QPixmap pixmapBlackSquare = QPixmap( ":/images/blackSquare.png" );
QPixmap pixmapWhiteSquare = QPixmap( ":/images/whiteSquare.png" );
// Establish the Scene
QGraphicsScene scene;
scene.setSceneRect( -370.0, -370.0, 740.0, 740.0 );
// Set up the Board
QGraphicsPixmapItem pixmapItem0;
pixmapItem0.setPixmap( pixmapBlackSquare );
pixmapItem0.setPos( -370, 296 );
scene.addItem( &pixmapItem0 );
QGraphicsPixmapItem pixmapItem1;
pixmapItem1.setPixmap( pixmapWhiteSquare );
pixmapItem1.setPos( -296, 296 );
scene.addItem( &pixmapItem1 );
// Establish the View
QGraphicsView view( &scene );
view.setGeometry( 400, 200, 760, 760 );
view.setRenderHints( QPainter::Antialiasing );
view.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
And then the unsuccessful test with the vector:
// ChessVectorTest2
// MDJ 2016/11/02
// Qt 5.7 - Qt Creator 4.0.2 - Qt Widgets Application
// No changes to files other than this main.cpp - except:
// Added line "RESOURCES += application.qrc" to ChessTest2.pro.
// Added images folder with files:
// blackSquare.png
// whiteSquare.png
// Added application.qrc Resources file:
// <!DOCTYPE RCC><RCC version="1.0">
// <qresource>
// <file>images/blackSquare.png</file>
// <file>images/whiteSquare.png</file>
// </qresource>
// </RCC>
// This test compiles:
// but displays nothing
// and reports no errors
#include "mainwindow.h"
#include <QApplication>
#include <QPixmap>
#include <QGraphicsPixmapItem>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QVector>
int main( int argc, char **argv )
{
// Load the Resource Graphics
// Establish the Scene
scene.setSceneRect( -370.0, -370.0, 740.0, 740.0 );
// Set up the Board
boardVector[ 0 ]->setPixmap( pixmapBlackSquare );
boardVector[ 0 ]->setPos( -370, 296 );
scene.addItem( boardVector[ 0 ] );
boardVector[ 1 ]->setPixmap( pixmapWhiteSquare );
boardVector[ 1 ]->setPos( -296, 296 );
scene.addItem( boardVector[ 1 ] );
// Establish the View
view.setGeometry( 400, 200, 760, 760 );
view.
setRenderHints( QPainter::Antialiasing );
view.show();
return app.exec();
}
// ChessVectorTest2
// MDJ 2016/11/02
// Qt 5.7 - Qt Creator 4.0.2 - Qt Widgets Application
// No changes to files other than this main.cpp - except:
// Added line "RESOURCES += application.qrc" to ChessTest2.pro.
// Added images folder with files:
// blackSquare.png
// whiteSquare.png
// Added application.qrc Resources file:
// <!DOCTYPE RCC><RCC version="1.0">
// <qresource>
// <file>images/blackSquare.png</file>
// <file>images/whiteSquare.png</file>
// </qresource>
// </RCC>
// This test compiles:
// but displays nothing
// and reports no errors
#include "mainwindow.h"
#include <QApplication>
#include <QPixmap>
#include <QGraphicsPixmapItem>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QVector>
int main( int argc, char **argv )
{
QApplication app(argc, argv);
// Load the Resource Graphics
QPixmap pixmapBlackSquare = QPixmap( ":/images/blackSquare.png" );
QPixmap pixmapWhiteSquare = QPixmap( ":/images/whiteSquare.png" );
// Establish the Scene
QGraphicsScene scene;
scene.setSceneRect( -370.0, -370.0, 740.0, 740.0 );
// Set up the Board
QVector< QGraphicsPixmapItem* > boardVector( 2 );
boardVector[ 0 ]->setPixmap( pixmapBlackSquare );
boardVector[ 0 ]->setPos( -370, 296 );
scene.addItem( boardVector[ 0 ] );
boardVector[ 1 ]->setPixmap( pixmapWhiteSquare );
boardVector[ 1 ]->setPos( -296, 296 );
scene.addItem( boardVector[ 1 ] );
// Establish the View
QGraphicsView view( &scene );
view.setGeometry( 400, 200, 760, 760 );
view.setRenderHints( QPainter::Antialiasing );
view.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Without any error messages, I'm pretty much lost.
Added after 10 minutes:
To d_stranz:
I'm trying to organize the QGraphicsPixmapItems into a QVector and then add the individual vector entries to the scene. This will facilitate subsequent logic.
This is a chess board. The squares are added to the scene, and the pieces will be added with the squares as parents. This will facilitate checking how many attacks are currently leveled at a given square and the legality of proposed moves. It will also facilitate the actual moves themselves by setting a new parent for the piece in question.
Bookmarks