Results 1 to 6 of 6

Thread: A small annoying problem in my QGraphicsScene

  1. #1
    Join Date
    Oct 2012
    Posts
    13
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default A small annoying problem in my QGraphicsScene

    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 :

    Screen shot 2013-01-26 at 6.09.56 PM.jpg

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

    Screen shot 2013-01-26 at 6.10.03 PM.jpg

    Parts of the code related to this :

    Qt Code:
    1. #ifndef ChessElement_H
    2. #define ChessElement_H
    3. #include <QGraphicsItem>
    4. Class QPainter;
    5.  
    6. class ChessElement : public QGraphicsItem
    7. {
    8.  
    9. public:
    10.  
    11. QImage *g;
    12. char type;
    13. char identity;
    14. int color;
    15. int rank;
    16. bool isOccupied;
    17. bool movflag;
    18. int rawCount;
    19. int rawRank;
    20.  
    21.  
    22.  
    23. public : ChessElement(QImage*,int,bool,char,int,char,int,int);
    24.  
    25. public :QRectF boundingRect() const ;
    26.  
    27. public :void paint(QPainter*, const QStyleOptionGraphicsItem*,QWidget *);
    28.  
    29.  
    30.  
    31. };
    32.  
    33. #endif // ChessElement_H
    To copy to clipboard, switch view to plain text mode 

    Paint function :
    Qt Code:
    1. QRectF ChessElement::boundingRect() const
    2. {
    3.  
    4. return QRectF(0,0,30,30);
    5.  
    6. }
    7.  
    8. void ChessElement:: paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
    9. QWidget *widget)
    10. {
    11. QPoint *s = new QPoint(0,0);
    12. painter->drawImage(*s,*g);
    13. delete s;
    14.  
    15.  
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: A small annoying problem in my QGraphicsScene

    I guess is that the order of the items is causing this.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Oct 2012
    Posts
    13
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: A small annoying problem in my QGraphicsScene

    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.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: A small annoying problem in my QGraphicsScene

    It makes me think there is some problem with either boundingRect() or with paint()

    Try with this version of drawImage()
    Qt Code:
    1. void QPainter::drawImage ( const QPointF & point, const QImage & image, const QRectF & source, Qt::ImageConversionFlags flags = Qt::AutoColor )
    To copy to clipboard, switch view to plain text mode 
    source rect will be the bounding rect
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. The following user says thank you to Santosh Reddy for this useful post:

    AtlasS (27th January 2013)

  6. #5
    Join Date
    Oct 2012
    Posts
    13
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: A small annoying problem in my QGraphicsScene

    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)

  7. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: A small annoying problem in my QGraphicsScene

    Are you embedding images as resources in the exe file, if so check there size too
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  8. The following user says thank you to Santosh Reddy for this useful post:

    AtlasS (28th January 2013)

Similar Threads

  1. Annoying problem with Qt 4.6.3 on Ubuntu 10.04
    By srikanth_trulyit in forum Qt Programming
    Replies: 4
    Last Post: 24th August 2010, 08:00
  2. Small problem
    By NewLegend in forum Qt Programming
    Replies: 1
    Last Post: 23rd July 2010, 21:52
  3. i have a problem in a very small application?
    By coder1985 in forum Qt Programming
    Replies: 3
    Last Post: 22nd November 2007, 17:09
  4. a annoying problem about QTextCursor
    By kaos33 in forum Qt Programming
    Replies: 1
    Last Post: 31st August 2006, 05:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.