返回介绍

QLayoutIterator Class

发布于 2019-10-04 15:00:55 字数 3997 浏览 863 评论 0 收藏 0

The QLayoutIterator class provides iterators over QLayoutItem. More...

#include <qlayout.h>

List of all member functions.

Public Members

  • QLayoutIterator ( QGLayoutIterator*gi )
  • QLayoutIterator ( constQLayoutIterator&i )
  • ~QLayoutIterator ()
  • QLayoutIterator & operator= ( constQLayoutIterator&i )
  • QLayoutItem * operator++ ()
  • QLayoutItem * current ()
  • QLayoutItem * takeCurrent ()
  • void deleteCurrent ()

Detailed Description

The QLayoutIterator class provides iterators over QLayoutItem.

Use QLayoutItem::iterator() to create an iterator over a layout.

QLayoutIterator uses explicit sharing with a reference count. If an iterator is copied and one of the copies is modified, both iterators will be modified.

A QLayoutIterator is not protected against changes in its layout. If the layout is modified or deleted the iterator will become invalid. It is not possible to test for validity. It is safe to delete an invalid layout; any other access may lead to an illegal memory reference and the abnormal termination of the program.

Calling takeCurrent() or deleteCurrent() leaves the iterator in a valid state, but may invalidate any other iterators that access the same layout.

The following code will draw a rectangle for each layout item in the layout structure of the widget.

    static void paintLayout( QPainter *p, QLayoutItem *lay )
    {
        QLayoutIterator it = lay->iterator();
        QLayoutItem *child;
        while ( (child = it.current()) != 0 ) {
            paintLayout( p, child );
            it.next();
        }
        p->drawRect( lay->geometry() );
    }
    void ExampleWidget::paintEvent( QPaintEvent * )
    {
        QPainter p( this );
        if ( layout() )
            paintLayout( &p, layout() );
    }
    

All the functionality of QLayoutIterator is implemented by subclasses of QGLayoutIterator. QLayoutIterator itself is not designed to be subclassed.

See also Widget Appearance and Style and Layout Management.


Member Function Documentation

QLayoutIterator::QLayoutIterator ( QGLayoutIterator*gi )

Constructs an iterator based on gi. The constructed iterator takes ownership of gi and will delete it.

This constructor is provided for layout implementors. Application programmers should use QLayoutItem::iterator() to create an iterator over a layout.

QLayoutIterator::QLayoutIterator ( constQLayoutIterator&i )

Creates a shallow copy of i, i.e. if the copy is modified, then the original will also be modified.

QLayoutIterator::~QLayoutIterator ()

Destroys the iterator.

QLayoutItem* QLayoutIterator::current ()

Returns the current item, or 0 if there is no current item.

void QLayoutIterator::deleteCurrent ()

Removes and deletes the current child item from the layout and moves the iterator to the next item. This iterator will still be valid, but any other iterator over the same layout may become invalid.

QLayoutItem* QLayoutIterator::operator++ ()

Moves the iterator to the next child item and returns that item, or 0 if there is no such item.

QLayoutIterator& QLayoutIterator::operator= ( constQLayoutIterator&i )

Assigns i to this iterator and returns a reference to this iterator.

QLayoutItem* QLayoutIterator::takeCurrent ()

Removes the current child item from the layout without deleting it, and moves the iterator to the next item. Returns the removed item, or 0 if there was no item to be removed. This iterator will still be valid, but any other iterator over the same layout may become invalid.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文