Results 1 to 2 of 2

Thread: Puzzle Example on Qt's website

  1. #1
    Join Date
    May 2010
    Posts
    7
    Qt products
    Qt4

    Exclamation Puzzle Example on Qt's website

    Sup guys, I'm working on a project and it shares some similarities with the puzzle that's in the QT doc's:

    http://doc.trolltech.com/4.5/itemviews-puzzle.html

    Anyways, I've understood most of the code but something has been bugging me:

    Is the puzzleWidget class the whole puzzle or a single puzzle piece? I'm confused since in the constructor the puzzleWidget is declaring a size of 400 by 400, which is the size of the puzzle(5 by 5 pieces of 80px's length).

    But, I haven't been able to find the point where the widget separates the pieces into a regular board. There's no gridlayout and the two loops inside the .cpp don't seem to create each individual pieces.

    In short, I'm trying to understand how they managed to make the grid.

    thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Puzzle Example on Qt's website

    There isn't a QGridLayout used, but I assume you already know that.

    The widget is devided into several target squares, each 80x80.
    A position is calculated by using the piece location. This is done with the following function:

    Qt Code:
    1. const QRect PuzzleWidget::targetSquare(const QPoint &position) const
    2. {
    3. return QRect(position.x()/80 * 80, position.y()/80 * 80, 80, 80);
    4. }
    To copy to clipboard, switch view to plain text mode 

    If you look at the code, you'll see several lists, one for the pieces themselves, one for the position, etc...
    When you drop a piece, the location and the piece are added to these lists. Then when you select a piece and move it around, this location is used to calculate if you're on the target rect or not.

Similar Threads

  1. Create a Website
    By Trader in forum Newbie
    Replies: 8
    Last Post: 10th July 2012, 07:27
  2. Can QWebPage see changes in a website
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 15th August 2009, 23:23
  3. Replies: 0
    Last Post: 3rd June 2009, 04:26
  4. An example puzzle me, please help
    By HelloDan in forum Newbie
    Replies: 6
    Last Post: 8th March 2009, 08:47
  5. how does a website such as google gets income
    By babu198649 in forum General Discussion
    Replies: 1
    Last Post: 19th April 2008, 12:06

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.