PDA

View Full Version : A small annoying problem in my QGraphicsScene



AtlasS
26th January 2013, 16:16
I already asked a question about this application.

I'm designing a chess application (with extended controls), but the movement of the peaces take place in a QGraphicsScene, designed to hold the board.

The board is sharp and pretty without movements :

8628

When I move an element (next to the frame) this happens :

8629

Parts of the code related to this :


#ifndef ChessElement_H
#define ChessElement_H
#include <QGraphicsItem>
Class QPainter;

class ChessElement : public QGraphicsItem
{

public:

QImage *g;
char type;
char identity;
int color;
int rank;
bool isOccupied;
bool movflag;
int rawCount;
int rawRank;



public : ChessElement(QImage*,int,bool,char,int,char,int,in t);

public :QRectF boundingRect() const ;

public :void paint(QPainter*, const QStyleOptionGraphicsItem*,QWidget *);



};

#endif // ChessElement_H


Paint function :


QRectF ChessElement::boundingRect() const
{

return QRectF(0,0,30,30);

}

void ChessElement:: paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
QPoint *s = new QPoint(0,0);
painter->drawImage(*s,*g);
delete s;



}

what is causing this white space ? I is it related to the re-drawing of items after movement.

Santosh Reddy
26th January 2013, 16:41
I guess is that the order of the items is causing this.

AtlasS
26th January 2013, 23:27
Santosh Reddy, thank you for replying.

When I minimize the window & enlarge, the white space is removed, the board becomes normal again.

I placed the frame as the first element in the scene.

Santosh Reddy
26th January 2013, 23:47
It makes me think there is some problem with either boundingRect() or with paint()

Try with this version of drawImage()

void QPainter::drawImage ( const QPointF & point, const QImage & image, const QRectF & source, Qt::ImageConversionFlags flags = Qt::AutoColor )
source rect will be the bounding rect

AtlasS
27th January 2013, 10:40
Thank you very much. I will try this function once I'm done with scanning the code again for missing things.

I'm very sorry but I have another question : my program was initially 13 MB, now its size has increased to 14.8 MB, is that too much for a chess game ?
I mean in your experience : do you think such application can be built with lesser size ? (using the same quality & extensions of images I used here ?? )
and if I used Qt's native painting functions to paint my chess elements, would it be lesser in size ?

Extensions used : PNG.
Quality : 100% (photoshop)

Santosh Reddy
27th January 2013, 14:53
Are you embedding images as resources in the exe file, if so check there size too