Results 1 to 3 of 3

Thread: QGridStarLayout - A Qt grid layout identical to WPF's star sized grid

  1. #1
    Join Date
    Nov 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default QGridStarLayout - A Qt grid layout identical to WPF's star sized grid

    Hey folks, I've had to go about designing my own layout that worked as a clone of WPF's Grid with "star sizing" capabilities, so I've done just that.

    For more information on how star sizing works, please refer to this Stack Overflow post:
    http://stackoverflow.com/questions/1...r-do-width-100

    Example usage:
    Qt Code:
    1. QGridDefinition mainGridDef;
    2.  
    3. mainGridDef.RowDefinition(0.03f);
    4. mainGridDef.RowDefinition(0.08f);
    5. mainGridDef.RowDefinition(0.94f);
    6. mainGridDef.RowDefinition(0.08f);
    7. mainGridDef.RowDefinition(0.03f);
    8.  
    9. mainGridDef.ColumnDefinition(0.03f);
    10. mainGridDef.ColumnDefinition(0.2f);
    11. mainGridDef.ColumnDefinition(0.03f);
    12. mainGridDef.ColumnDefinition();
    13.  
    14. QGridStarLayout *mainGrid = new QGridStarLayout(mainGridDef);
    15.  
    16. mainGrid->addWidget(new QPushButton("Test"), 1, 1);
    17. mainGrid->addWidget(new QPushButton("Test"), 3, 1);
    18.  
    19. QGridDefinition subGridDef;
    20.  
    21. subGridDef.RowDefinition(0.03f);
    22. subGridDef.RowDefinition(0.15f);
    23. subGridDef.RowDefinition();
    24. subGridDef.RowDefinition(0.03f);
    25.  
    26. subGridDef.ColumnDefinition(0.2f);
    27. subGridDef.ColumnDefinition(0.5f);
    28. subGridDef.ColumnDefinition(0.2f);
    29.  
    30. QGridStarLayout *subGrid = new QGridStarLayout(subGridDef);
    31.  
    32. subGrid->addWidget(new QScrollBar(Qt::Orientation::Horizontal), 1, 1);
    33.  
    34. mainGrid->addLayout(subGrid, 0, 3, 5);
    35.  
    36. centralWidget()->setLayout(mainGrid);
    To copy to clipboard, switch view to plain text mode 

    An imgur album detailing the above code and their definitions (blue is mainGrid, red is subGrid):
    http://imgur.com/a/aZDiH

    Source: https://github.com/Tannz0rz/QGridStarLayout

    Furthermore, if you see where the layout can be optimized, feel free to fork the repo and apply any necessary changes.

    Regards,
    Tannz0rz

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGridStarLayout - A Qt grid layout identical to WPF's star sized grid

    Nice work!

    Though I would recommend to follow Qt's style for naming methods, i.e. start with a lower case letter and probably name them in a way they say what they are doing.
    E.g. addRowDefinition() if it adds the definition of a new row. At least that is what it looks like.

    Also it is usually not a good idea to call a custom class QSomething, that makes it look like a class from Qt and gets people confused when they can't find it in the documentation.

    Cheers,
    _

  3. #3
    Join Date
    Nov 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: QGridStarLayout - A Qt grid layout identical to WPF's star sized grid

    Thank you for the suggestions! I'll fix the naming conventions soon.

Similar Threads

  1. Replies: 2
    Last Post: 4th September 2014, 12:09
  2. qdirmodel in grid layout
    By babu198649 in forum Newbie
    Replies: 1
    Last Post: 27th July 2008, 09:26
  3. How do I layout in a Grid?
    By DPinLV in forum Qt Tools
    Replies: 7
    Last Post: 10th August 2006, 02:37
  4. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 13:45
  5. Grid layout
    By nupul in forum Qt Programming
    Replies: 7
    Last Post: 21st April 2006, 22:15

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.