![]() adjusted( +left, +top, -right, -bottom) ĭoLayout() handles the layout if horizontalSpacing() or verticalSpacing() don't return the default value. GetContentsMargins( &left, &top, &right, &bottom) int FlowLayout ::doLayout( const QRect &rect, bool testOnly) const SizeHint() returns the preferred size of the layout and minimumSize() returns the minimum size of the layout. In this example, it calls doLayout() and passes the layout rect. SetGeometry() is normally used to do the actual layout, i.e., calculate the geometry of the layout's items. Size + = QSize( 2 *margin(), 2 *margin()) If (index > = 0 & & index minimumSize()) QLayoutItem *FlowLayout ::takeAt( int index) QLayoutItem *FlowLayout ::itemAt( int index) const ![]() If not, smartSpacing() will be called to calculate the spacing. If the value is less than or equal to 0, this value will be used. We implement horizontalSpacing() and verticalSpacing() to get hold of the spacing between the widgets inside the layout. Return smartSpacing( QStyle ::PM_LayoutVerticalSpacing) Return smartSpacing( QStyle ::PM_LayoutHorizontalSpacing) int FlowLayout ::horizontalSpacing() const void FlowLayout ::addItem( QLayoutItem *item)ĪddItem() is implemented to add items to the layout. When using addItem() the ownership of the layout items is transferred to the layout, and it is therefore the layout's responsibility to delete them. In this example we reimplement addItem(), which is a pure virtual function. By default, QLayout uses values provided by the current style (see QStyle::PixelMetric). In the constructor we call setContentsMargins() to set the left, top, right and bottom margin. : m_hSpace(hSpacing), m_vSpace(vSpacing) SetContentsMargins(margin, margin, margin, margin) įlowLayout ::FlowLayout( int margin, int hSpacing, int vSpacing) : QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing) We start off by looking at the constructor: FlowLayout ::FlowLayout( QWidget *parent, int margin, int hSpacing, int vSpacing) doLayout() lays out the layout items, while the smartSpacing() function calculates the spacing between them. We also declare two private methods, doLayout() and smartSpacing(). These functions add items to the layout and handle their orientation and geometry. We reimplement functions inherited from QLayout. Int smartSpacing( QStyle ::PixelMetric pm) const Int doLayout( const QRect &rect, bool testOnly) const Qt ::Orientations expandingDirections() const class FlowLayout : public QLayoutįlowLayout( QWidget *parent, int margin = - 1, int hSpacing = - 1, int vSpacing = - 1) įlowLayout( int margin = - 1, int hSpacing = - 1, int vSpacing = - 1) It is a custom layout class that arranges its child widgets horizontally and vertically. ![]() We will only document the definition and implementation of FlowLayout below. The Flowlayout class mainly uses QLayout and QWidgetItem, while the Window uses QWidget and QLabel. The items are first laid out horizontally and then vertically when each line in the layout runs out of space. The Flow Layout example demonstrates a custom layout that arranges child widgets from left to right and top to bottom in a top-level widget.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |