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:
Code:
QGridDefinition mainGridDef;
mainGridDef.RowDefinition(0.03f);
mainGridDef.RowDefinition(0.08f);
mainGridDef.RowDefinition(0.94f);
mainGridDef.RowDefinition(0.08f);
mainGridDef.RowDefinition(0.03f);
mainGridDef.ColumnDefinition(0.03f);
mainGridDef.ColumnDefinition(0.2f);
mainGridDef.ColumnDefinition(0.03f);
mainGridDef.ColumnDefinition();
QGridStarLayout *mainGrid = new QGridStarLayout(mainGridDef);
QGridDefinition subGridDef;
subGridDef.RowDefinition(0.03f);
subGridDef.RowDefinition(0.15f);
subGridDef.RowDefinition();
subGridDef.RowDefinition(0.03f);
subGridDef.ColumnDefinition(0.2f);
subGridDef.ColumnDefinition(0.5f);
subGridDef.ColumnDefinition(0.2f);
QGridStarLayout *subGrid = new QGridStarLayout(subGridDef);
subGrid
->addWidget
(new QScrollBar(Qt
::Orientation::Horizontal),
1,
1);
mainGrid->addLayout(subGrid, 0, 3, 5);
centralWidget()->setLayout(mainGrid);
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
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,
_
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.