Results 1 to 4 of 4

Thread: setheightforwidth not working?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2021
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default setheightforwidth not working?

    Hi everybody. I've poked a bit at QT before but I'm really a newbie. Now I'm attempting to put together a version of the classic minesweeper game.

    This kind of game really needs square cells in the grid. I thought I could get that by applying the "heightforwidth" property to the qpushbuttons that make up each tile.
    Here's an example of what I get:

    Screenshot_2021-09-07_11-09-44.jpg

    Here's the code for the cell:

    Qt Code:
    1. class GridCell : public QPushButton
    2. {
    3. bool Bomb;
    4. GridPos Pos;
    5.  
    6. public:
    7. GridCell() {}
    8. virtual ~GridCell() {}
    9.  
    10. GridCell (QGridLayout *GridLayout, const GridPos &P) : QPushButton ()
    11. {
    12. Pos = P;
    13. GridLayout->addWidget(this, Pos.y, Pos.x);
    14.  
    15. QSizePolicy p(sizePolicy());
    16. p.setHeightForWidth (true);
    17. p.setVerticalPolicy (QSizePolicy::Expanding);
    18. p.setHorizontalPolicy (QSizePolicy::Expanding);
    19. p.setHorizontalStretch (1);
    20. p.setVerticalStretch (1);
    21. setSizePolicy (p);
    22.  
    23. setText("K");
    24. }
    25.  
    26. void SetBomb (bool B = true)
    27. {
    28. Bomb = B;
    29. }
    30.  
    31. bool IsBomb ()
    32. {
    33. return Bomb;
    34. }
    35. };
    To copy to clipboard, switch view to plain text mode 

    I've tried a lot of different things but guess I'm misunderstanding some fundamental concept.

    A little help please?
    Last edited by d_stranz; 8th September 2021 at 00:10. Reason: missing [code] tags

Similar Threads

  1. Qml is not working
    By sanjeet in forum Qt for Embedded and Mobile
    Replies: 7
    Last Post: 14th April 2016, 08:38
  2. Replies: 7
    Last Post: 24th September 2012, 07:17
  3. Working with map
    By naptizaN in forum Newbie
    Replies: 4
    Last Post: 28th August 2012, 12:57
  4. MVC example not working
    By yyiu002 in forum Newbie
    Replies: 1
    Last Post: 30th June 2010, 00:07
  5. My first app not working
    By Noks in forum Newbie
    Replies: 6
    Last Post: 2nd February 2010, 16:34

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.