⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qsplitter.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    a resize operation, call setOpaqueResize(false).    The initial distribution of size between the widgets is determined by the    initial size of each widget. You can also use setSizes() to set the sizes    of all the widgets. The function sizes() returns the sizes set by the user.    Alternatively, you can save and restore the sizes of the widgets from a    QByteArray using saveState() and restoreState() respectively.    When you hide() a child its space will be distributed among the    other children. It will be reinstated when you show() it again.    \sa QSplitterHandle, QHBoxLayout, QVBoxLayout, QTabWidget*//*!    Constructs a horizontal splitter with the \a parent    arguments is passed on to the QFrame constructor.    \sa setOrientation()*/QSplitter::QSplitter(QWidget *parent)    : QFrame(*new QSplitterPrivate, parent){    Q_D(QSplitter);    d->orient = Qt::Horizontal;    d->init();}/*!    Constructs a splitter with the given \a orientation and \a parent.    \sa setOrientation()*/QSplitter::QSplitter(Qt::Orientation orientation, QWidget *parent)    : QFrame(*new QSplitterPrivate, parent){    Q_D(QSplitter);    d->orient = orientation;    d->init();}/*!    Destroys the splitter. All children are deleted.*/QSplitter::~QSplitter(){    Q_D(QSplitter);    while (!d->list.isEmpty())        delete d->list.takeFirst();}/*!    Updates the splitter's state. You should not need to call this    function.*/void QSplitter::refresh(){    Q_D(QSplitter);    d->recalc(true);}/*!    \property QSplitter::orientation    \brief the orientation of the splitter    By default the orientation is horizontal (i.e., the widgets are    laid out side by side). The possible orientations are    Qt::Horizontal and Qt::Vertical.    \sa QSplitterHandle::orientation()*/void QSplitter::setOrientation(Qt::Orientation orientation){    Q_D(QSplitter);    if (d->orient == orientation)        return;    if (!testAttribute(Qt::WA_WState_OwnSizePolicy)) {        QSizePolicy sp = sizePolicy();        sp.transpose();        setSizePolicy(sp);        setAttribute(Qt::WA_WState_OwnSizePolicy, false);    }    d->orient = orientation;    for (int i = 0; i < d->list.size(); ++i) {        QSplitterLayoutStruct *s = d->list.at(i);        s->handle->setOrientation(orientation);    }    d->recalc(isVisible());}Qt::Orientation QSplitter::orientation() const{    Q_D(const QSplitter);    return d->orient;}/*!    \property QSplitter::childrenCollapsible    \brief whether child widgets can be resized down to size 0 by the user    By default, children are collapsible. It is possible to enable    and disable the collapsing of individual children using    setCollapsible().    \sa setCollapsible()*/void QSplitter::setChildrenCollapsible(bool collapse){    Q_D(QSplitter);    d->childrenCollapsible = collapse;}bool QSplitter::childrenCollapsible() const{    Q_D(const QSplitter);    return d->childrenCollapsible;}/*!    Sets whether the child widget at index \a index is collapsible to \a collapse.    By default, children are collapsible, meaning that the user can    resize them down to size 0, even if they have a non-zero    minimumSize() or minimumSizeHint(). This behavior can be changed    on a per-widget basis by calling this function, or globally for    all the widgets in the splitter by setting the \l    childrenCollapsible property.    \sa childrenCollapsible*/void QSplitter::setCollapsible(int index, bool collapse){    Q_D(QSplitter);    if (index < 0 || index >= d->list.size()) {        qWarning("QSplitter::setCollapsible: Index %d out of range", index);        return;    }    d->list.at(index)->collapsible = collapse ? 1 : 0;}/*!    Returns true if the widget at \a index is collapsible, otherwise returns false*/bool QSplitter::isCollapsible(int index) const{    Q_D(const QSplitter);    if (index < 0 || index >= d->list.size()) {        qWarning("QSplitter::isCollapsible: Index %d out of range", index);        return false;    }    return d->list.at(index)->collapsible;}/*!    \reimp*/void QSplitter::resizeEvent(QResizeEvent *){    Q_D(QSplitter);    d->doResize();}/*!    Adds the given \a widget to the splitter's layout after all the other    items.    If \a widget is already in the splitter, it will be moved to the new position.    \sa insertWidget() widget() indexOf()*/void QSplitter::addWidget(QWidget *widget){    Q_D(QSplitter);    insertWidget(d->list.count(), widget);}/*!    Inserts the \a widget specified into the splitter's layout at the    given \a index.    If \a widget is already in the splitter, it will be moved to the new position.    if \a index is an invalid index, then the widget will be inserted at the end.    \sa addWidget() indexOf() widget()*/void QSplitter::insertWidget(int index, QWidget *widget){    Q_D(QSplitter);    QBoolBlocker b(d->blockChildAdd);    bool needShow = isVisible() &&                    !(widget->isHidden() && widget->testAttribute(Qt::WA_WState_ExplicitShowHide));    if (widget->parentWidget() != this)        widget->setParent(this);    if (needShow)        widget->show();    d->insertWidget(index, widget);    d->recalc(isVisible());}/*!    \fn int QSplitter::indexOf(QWidget *widget) const    Returns the index in the splitter's layout of the specified \a widget. This    also works for handles.    Handles are numbered from 0. There are as many handles as there    are child widgets, but the handle at position 0 is always hidden.    \sa count(), widget()*/int QSplitter::indexOf(QWidget *w) const{    Q_D(const QSplitter);    for (int i = 0; i < d->list.size(); ++i) {        QSplitterLayoutStruct *s = d->list.at(i);        if (s->widget == w || s->handle == w)            return i;    }    return -1;}/*!    Returns a new splitter handle as a child widget of this splitter.    This function can be reimplemented in subclasses to provide support    for custom handles.    \sa handle(), indexOf()*/QSplitterHandle *QSplitter::createHandle(){    Q_D(QSplitter);    return new QSplitterHandle(d->orient, this);}/*!    Returns the handle to the left (or above) for the item in the    splitter's layout at the given \a index. The handle at index 0 is    always hidden.    For right-to-left languages such as Arabic and Hebrew, the layout    of horizontal splitters is reversed. The handle will be to the    right of the widget at \a index.    \sa count(), widget(), indexOf(), createHandle(), setHandleWidth()*/QSplitterHandle *QSplitter::handle(int index) const{    Q_D(const QSplitter);    if (index < 0 || index >= d->list.size())        return 0;    return d->list.at(index)->handle;}/*!    Returns the widget at the given \a index in the splitter's layout.    \sa count(), handle(), indexOf(), insertWidget()*/QWidget *QSplitter::widget(int index) const{    Q_D(const QSplitter);    if (index < 0 || index >= d->list.size())        return 0;    return d->list.at(index)->widget;}/*!    Returns the number of widgets contained in the splitter's layout.    \sa widget(), handle()*/int QSplitter::count() const{    Q_D(const QSplitter);    return d->list.count();}/*!    \reimp    Tells the splitter that the child widget described by \a c has been    inserted or removed.    This method is also used to handle the situation where a widget is created    with the splitter as a parent but not explicitly added with insertWidget()    or addWidget(). This is for compatibility and not the recommended way of    putting widgets into a splitter in new code. Please use insertWidget() or    addWidget() in new code.    \sa addWidget() insertWidget()*/void QSplitter::childEvent(QChildEvent *c){    Q_D(QSplitter);    if (!c->child()->isWidgetType())        return;    QWidget *w = static_cast<QWidget*>(c->child());    if (c->added() && !d->blockChildAdd && !w->isWindow() && !d->findWidget(w)) {        addWidget(w);    } else  if (c->type() == QEvent::ChildRemoved) {        for (int i = 0; i < d->list.size(); ++i) {            QSplitterLayoutStruct *s = d->list.at(i);            if (s->widget == w) {                d->list.removeAt(i);                delete s;                d->recalc(isVisible());                return;            }        }    }}/*!    Displays a rubber band at position \a pos. If \a pos is negative, the    rubber band is removed.*/void QSplitter::setRubberBand(int pos){    Q_D(QSplitter);    if (pos < 0) {        if (d->rubberBand)            d->rubberBand->hide();        return;    }    QRect r = contentsRect();    const int rBord = 3; // customizable?    int hw = handleWidth();    if (!d->rubberBand) {        QBoolBlocker block(d->blockChildAdd);        d->rubberBand = new QRubberBand(QRubberBand::Line, this);    }    if (d->orient == Qt::Horizontal)        d->rubberBand->setGeometry(QRect(QPoint(pos + hw / 2 - rBord, r.y()),                                         QSize(2 * rBord, r.height())));    else        d->rubberBand->setGeometry(QRect(QPoint(r.x(), pos + hw / 2 - rBord),                                   QSize(r.width(), 2 * rBord)));    if (!d->rubberBand->isVisible())        d->rubberBand->show();}/*!    \reimp*/bool QSplitter::event(QEvent *e){    Q_D(QSplitter);    switch (e->type()) {    case QEvent::Hide:        // Reset firstShow to false here since things can be done to the splitter in between        if (!d->firstShow)            d->firstShow = true;        break;    case QEvent::Show:        if (!d->firstShow)            break;        d->firstShow = false;        // fall through    case QEvent::HideToParent:    case QEvent::ShowToParent:    case QEvent::LayoutRequest:#ifdef QT3_SUPPORT    case QEvent::LayoutHint:#endif        d->recalc(isVisible());        break;    default:        ;    }    return QWidget::event(e);}/*!    \fn QSplitter::splitterMoved(int pos, int index)    This signal is emitted when the splitter handle at a particular \a    index has been moved to position \a pos.    For right-to-left languages such as Arabic and Hebrew, the layout    of horizontal splitters is reversed. \a pos is then the    distance from the right edge of the widget.    \sa moveSplitter()*//*!    Moves the left or top edge of the splitter handle at \a index as    close as possible to position \a pos, which is the distance from the    left or top edge of the widget.    For right-to-left languages such as Arabic and Hebrew, the layout    of horizontal splitters is reversed. \a pos is then the distance    from the right edge of the widget.    \sa splitterMoved(), closestLegalPosition(), getRange()*/void QSplitter::moveSplitter(int pos, int index){    Q_D(QSplitter);    QSplitterLayoutStruct *s = d->list.at(index);    int farMin;    int min;    int max;    int farMax;#ifdef QSPLITTER_DEBUG    int debugp = pos;#endif    pos = d->adjustPos(pos, index, &farMin, &min, &max, &farMax);    int oldP = d->pick(s->rect.topLeft());#ifdef QSPLITTER_DEBUG    qDebug() << "QSplitter::moveSplitter" << debugp << index << "adjusted" << pos << "oldP" << oldP;#endif    QVarLengthArray<int, 32> poss(d->list.count());    QVarLengthArray<int, 32> ws(d->list.count());    bool upLeft;    d->doMove(false, pos, index, +1, (d->collapsible(s) && (pos > max)), poss.data(), ws.data());    d->doMove(true, pos, index - 1, +1, (d->collapsible(index - 1) && (pos < min)), poss.data(), ws.data());    upLeft = (pos < oldP);    int wid, delta, count = d->list.count();    if (upLeft) {        wid = 0;        delta = 1;    } else {        wid = count - 1;        delta = -1;    }    for (; wid >= 0 && wid < count; wid += delta) {        QSplitterLayoutStruct *sls = d->list.at( wid );        if (!sls->widget->isHidden())

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -