专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > 软件架构设计

QT:QLayoutItem

发布时间:2011-06-20 02:11:12 文章来源:www.iduyao.cn 采编人员:星星草
QT::QLayoutItem
QLayoutItem类参考
QLayoutItem为布局操作提供了抽象条款。
#include<QLayoutItem>

Inherited by: QLayout, QSpacerItem, and QWidgetItem.

    

Detailed Description:
QLayoutItem为布局操作提供了抽象条款。该类可用于自定义布局。
纯虚函数的提供用于返回与布局相关的信息,包括 sizeHint(), minimumSize(), maximumSize(),expanding().
布局几何可以通过setGeometry()和geometry()设置和获取。
对其方式可以通过setAlignment()和alignment()设置和获取。
函数isEmpty()可用于判断一个布局项目是否为空。如果具体的实例是一个QWidget类对象,则可以通过widget()
返回布局。类似的函数还有 layout() 和 spacerItem().
有些布局中高度和宽度存在关联性,这些也可以通过调用 hasHeightForWidth(), heightForWidth(), 
minimumHeightForWidth(). 加以解释


Member Function Documentation
      QLayoutItem::QLayoutItem ( Qt::Alignment alignment = 0 )
      用指定的对齐方式构建一个布局对象,并非所有的子类都支持该对齐方式。
      
      QLayoutItem::~QLayoutItem () [virtual]
      虚拟析构函数
      
      Qt::Alignment QLayoutItem::alignment () const
      返回布局对象的对齐方式。
      
      QSizePolicy::ControlTypes QLayoutItem::controlTypes () const
      返回布局对象的控制类型,对于一个QWidgetItem,控制类型来源于窗口大小策略,对于一个QLayoutItem,
      控制类型来源于布局的内容。可参考QSizePolicy::controlType().
      
      Qt::Orientations QLayoutItem::expandingDirections () const [pure virtual]
      返回布局项目是否可利用比sizeHint()更多的空间,如果是Qt::Vertical 或 Qt::Horizontal 则意味着
      只能在一个方向扩张,Qt::Vertical | Qt::Horizontal则意味可同时在两个方向扩展空间。
      
      QRect QLayoutItem::geometry () const [pure virtual]
      翻译被布局覆盖的矩形几何体。
      
      bool QLayoutItem::hasHeightForWidth () const [virtual]
      如果布局的最佳高度依赖于宽度则返回true,否则返回false。默认实现返回false。
      在布局管理里重新实现该函数用于高度和宽度选定。
      
      int QLayoutItem::heightForWidth ( int w ) const [virtual]
      用给定的宽度参数w返回该布局项目的最佳高度。默认实现返回-1,并指定最佳高度是依赖于宽度的。
      调用函数hasHeightForWidth() 并用-1做测试会比本函数更快。
      一个典型的实现可能如下所示:
       int MyLayout::heightForWidth(int w) const
    {
       if (cache_dirty || cached_width != w) {
           // not all C++ compilers support "mutable"
           MyLayout *that = (MyLayout*)this;
           int h = calculateHeightForWidth(w);
           that->cached_hfw = h;
           return h;
       }
       return cached_hfw;
    }
    强烈推荐使用缓存,不然会消耗大量的执行时间。
    
    void QLayoutItem::invalidate () [virtual]
    使该布局的缓存无效。
    
    bool QLayoutItem::isEmpty () const [pure virtual]
    在子类中重新实现用以返回布局项目是否为空,或者包含其他组件。
    
    QLayout * QLayoutItem::layout () [virtual]
    如果该实体为布局类型则返回一个布局对象,都则返回0.该函数提供安全的强制类型转换。
    
    QSize QLayoutItem::maximumSize () const [pure virtual]
    在子类中重新实现用以返回布局的最大尺寸。
    
    int QLayoutItem::minimumHeightForWidth ( int w ) const [virtual]
    用布局窗口给定的宽度返回一个最小高度,默认实现简单的调用heightForWidth(w).
    
    QSize QLayoutItem::minimumSize () const [pure virtual]
    在子类中重新实现用以返回布局的最小尺寸。
    
    void QLayoutItem::setAlignment ( Qt::Alignment alignment )
    用参数alignment给定的值来设定布局的对齐方式。

    注意:该布局对齐方式仅支持QLayoutItem的子类同时会产生一个明显的效果,

除了QSpacerItem之外,其他布局实体都给布局提供一定的空白空间,

所有QLayoutItem的继承类都支持布局对齐方式。

    
    void QLayoutItem::setGeometry ( const QRect & r ) [pure virtual]
    在子类中重新实现用以设定布局的几何图形。
    
    QSize QLayoutItem::sizeHint () const [pure virtual]
    在子类中重新实现用以返回布局的最佳尺寸。
    
    QSpacerItem * QLayoutItem::spacerItem () [virtual]
    如果该实体是一个QSpacerItem 则直接返回它,否则返回0,该函数提供安全的类型转换。
    
    QWidget * QLayoutItem::widget () [virtual]
    如果该实体是一个QWidget则直接返回它,否则返回0,该函数提供安全的类型转换 。

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: