How about using QGraphicsScene::setBackgroundBrush() or QGraphicsScene::drawBackground()?
How about using QGraphicsScene::setBackgroundBrush() or QGraphicsScene::drawBackground()?
That would be a very bad suggestion since then I would have to change a lot of stuff in my code and make it better.![]()
A lot of stuff just to replace a pixmap item with a single call to the scene?
BTW. The suggestion is not bad just because you did something else incorrectly. If something is bad, then it's the design of your code, not a simple function call which you might use to solve your problem. Redesigning your code, even if it means rewriting a major part of the application, might result in many benefits and might overcome many future (or past) problems.
No, I was actually lucky. It wasn't so much work. The problem I had was that I had checks for how many items it would find at a position, now this number had to be lowered with 1. In fact, the code looks better now. And I have started to think about other things that I perhaps should do.
This is the problem I always seem to have. I have to start to get something working quickly, otherwise I tend to loose interest in it. At the same time I tend to introduce designflaws that has to be corrected later on.
I hope you noticed the smiley that was menat to indicate some kind of irony. You have never been wrong in your suggestions, I really appreaciate all the help people are giving me here. Thank you all.
Maybe you should prototype your code (for example with PyQt) so that you can release a preview quickly to maintain the level of interest and them implement it correctly with C++ once the major design issues are solved?
If I use the QGraphicsScene::drawBackground()as was suggested. Then what should that look like?
void Gameboard::drawBackground ( QPainter * painter, const QRectF & rect )
{
painter->drawPixmap( .............. , background_pic , ....... );
}
The dotted lines should probably contain rect in some way, but I'm not sure how.
It depends how do you want that background to behave. Should it repeat itself or should it scale to the size of the scene, etc. You might need to make a for loop that draws the pixmap multiple times to fill the "rect".
I only have one big pixmap that should fill up the entire background. The scene has the same size as the pixmap.
So just draw the pixmap.
Qt Code:
painter->drawPixmap(0,0, pixmap);To copy to clipboard, switch view to plain text mode
Bookmarks