本文整理汇总了C++中QTreeView::isExpanded方法的典型用法代码示例。如果您正苦于以下问题:C++ QTreeView::isExpanded方法的具体用法?C++ QTreeView::isExpanded怎么用?C++ QTreeView::isExpanded使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTreeView
的用法示例。
在下文中一共展示了QTreeView::isExpanded方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isExpanded
int TreeView::isExpanded(lua_State * L) // ( const QModelIndex & index ) const : bool
{
QTreeView* obj = QtObject<QTreeView>::check( L, 1);
QModelIndex* index = QtValue<QModelIndex>::check( L, 2 );
Util::push( L, obj->isExpanded( *index ) );
return 1;
}
示例2: handleExpand
void TreeCtrl::handleExpand(Root::Action & t)
{
QTreeView* tv = wnd();
QModelIndex i = tv->currentIndex();
ENABLED_IF( t, i.isValid() && ! tv->isExpanded( i ) );
tv->setExpanded( i, true );
}
示例3: editorEvent
bool RichTextDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
{
if (event->type() == QEvent::MouseButtonPress) {
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
if (mouseEvent->button() == Qt::LeftButton && mouseEvent->x() - option.rect.left() < 18 && model->hasChildren(index)) {
QTreeView *tree = static_cast<QTreeView *>(parent());
tree->setExpanded(index, !tree->isExpanded(index));
return true;
}
}
return false;
}
示例4: calculPopupGeometry
void pTreeComboBox::calculPopupGeometry()
{
if ( !mView ) {
return;
}
QStyle * const style = this->style();
// set current item and select it
view()->selectionModel()->setCurrentIndex( mCurrentIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
QFrame* container = mFrame;
QStyleOptionComboBox opt;
initStyleOption( &opt );
QRect listRect( style->subControlRect( QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxListBoxPopup, this ) );
QRect screen = popupGeometry( QApplication::desktop()->screenNumber( this ) );
QPoint below = mapToGlobal( listRect.bottomLeft() );
int belowHeight = screen.bottom() -below.y();
QPoint above = mapToGlobal( listRect.topLeft() );
int aboveHeight = above.y() -screen.y();
bool boundToScreen = !window()->testAttribute( Qt::WA_DontShowOnScreen );
listRect.moveTopLeft( mapToGlobal( rect().bottomLeft() ) );
listRect.setSize( QSize(
qMax( qMax( view()->viewport()->width(), mFrame->width() ), width() )
,
qMax( view()->viewport()->height(), mFrame->height() )
) );
const bool usePopup = style->styleHint( QStyle::SH_ComboBox_Popup, &opt, this );
{
int listHeight = 0;
int count = 0;
QStack<QModelIndex> toCheck;
toCheck.push( view()->rootIndex() );
#ifndef QT_NO_TREEVIEW
QTreeView* treeView = qobject_cast<QTreeView*>( view() );
if ( treeView && treeView->header() && !treeView->header()->isHidden() )
listHeight += treeView->header()->height();
#endif
while ( !toCheck.isEmpty() ) {
QModelIndex parent = toCheck.pop();
for ( int i = 0; i < model()->rowCount( parent ); ++i ) {
QModelIndex idx = model()->index( i, mModelColumn, parent );
if ( !idx.isValid() )
continue;
listHeight += view()->visualRect( idx ).height();
#ifndef QT_NO_TREEVIEW
if ( model()->hasChildren( idx ) && treeView && treeView->isExpanded( idx ) )
toCheck.push( idx );
#endif
++count;
if ( !usePopup && count > mMaxVisibleItems ) {
toCheck.clear();
break;
}
}
}
listRect.setHeight( listHeight );
}
{
// add the spacing for the grid on the top and the bottom;
int heightMargin = 0;
// add the frame of the container
int marginTop, marginBottom;
container->getContentsMargins( 0, &marginTop, 0, &marginBottom );
heightMargin += marginTop +marginBottom;
//add the frame of the view
view()->getContentsMargins( 0, &marginTop, 0, &marginBottom );
marginTop += 0/*static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->top*/;
marginBottom += 0/*static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->bottom*/;
heightMargin += marginTop +marginBottom;
listRect.setHeight( listRect.height() +heightMargin );
}
// Add space for margin at top and bottom if the style wants it.
if ( usePopup )
listRect.setHeight( listRect.height() +style->pixelMetric( QStyle::PM_MenuVMargin, &opt, this ) *2 );
// Make sure the popup is wide enough to display its contents.
if ( usePopup ) {
const int diff = sizeHint().width() /*d->computeWidthHint()*/ -width();
if ( diff > 0 )
listRect.setWidth( listRect.width() +diff );
}
//we need to activate the layout to make sure the min/maximum size are set when the widget was not yet show
container->layout()->activate();
//takes account of the minimum/maximum size of the container
listRect.setSize( listRect.size().expandedTo(container->minimumSize())
.boundedTo(container->maximumSize()));
// make sure the widget fits on screen
if (boundToScreen) {
if (listRect.width() > screen.width() )
listRect.setWidth(screen.width());
if (/*mapToGlobal(*/listRect/*.bottomRight())*/.x() > screen.right()) {
//.........这里部分代码省略.........
示例5: resizePopup
// -------------------------------------------------------------------------
void ctkTreeComboBox::resizePopup()
{
// copied from QComboBox.cpp
Q_D(ctkTreeComboBox);
QStyle * const style = this->style();
QWidget* container = qobject_cast<QWidget*>(this->view()->parent());
QStyleOptionComboBox opt;
this->initStyleOption(&opt);
QRect listRect(style->subControlRect(QStyle::CC_ComboBox, &opt,
QStyle::SC_ComboBoxListBoxPopup, this));
QRect screen = QApplication::desktop()->availableGeometry(
QApplication::desktop()->screenNumber(this));
QPoint below = this->mapToGlobal(listRect.bottomLeft());
int belowHeight = screen.bottom() - below.y();
QPoint above = this->mapToGlobal(listRect.topLeft());
int aboveHeight = above.y() - screen.y();
bool boundToScreen = !this->window()->testAttribute(Qt::WA_DontShowOnScreen);
const bool usePopup = style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this);
{
int listHeight = 0;
int count = 0;
QStack<QModelIndex> toCheck;
toCheck.push(this->view()->rootIndex());
#ifndef QT_NO_TREEVIEW
QTreeView *treeView = qobject_cast<QTreeView*>(this->view());
if (treeView && treeView->header() && !treeView->header()->isHidden())
listHeight += treeView->header()->height();
#endif
while (!toCheck.isEmpty())
{
QModelIndex parent = toCheck.pop();
for (int i = 0; i < this->model()->rowCount(parent); ++i)
{
QModelIndex idx = this->model()->index(i, this->modelColumn(), parent);
if (!idx.isValid())
{
continue;
}
listHeight += this->view()->visualRect(idx).height(); /* + container->spacing() */;
#ifndef QT_NO_TREEVIEW
if (this->model()->hasChildren(idx) && treeView && treeView->isExpanded(idx))
{
toCheck.push(idx);
}
#endif
++count;
if (!usePopup && count > this->maxVisibleItems())
{
toCheck.clear();
break;
}
}
}
listRect.setHeight(listHeight);
}
{
// add the spacing for the grid on the top and the bottom;
int heightMargin = 0;//2*container->spacing();
// add the frame of the container
int marginTop, marginBottom;
container->getContentsMargins(0, &marginTop, 0, &marginBottom);
heightMargin += marginTop + marginBottom;
//add the frame of the view
this->view()->getContentsMargins(0, &marginTop, 0, &marginBottom);
//marginTop += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(this->view()))->top;
//marginBottom += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(this->view()))->bottom;
heightMargin += marginTop + marginBottom;
listRect.setHeight(listRect.height() + heightMargin);
}
// Add space for margin at top and bottom if the style wants it.
if (usePopup)
{
listRect.setHeight(listRect.height() + style->pixelMetric(QStyle::PM_MenuVMargin, &opt, this) * 2);
}
// Make sure the popup is wide enough to display its contents.
if (usePopup)
{
const int diff = d->computeWidthHint() - this->width();
if (diff > 0)
{
listRect.setWidth(listRect.width() + diff);
}
}
//we need to activate the layout to make sure the min/maximum size are set when the widget was not yet show
container->layout()->activate();
//takes account of the minimum/maximum size of the container
listRect.setSize( listRect.size().expandedTo(container->minimumSize())
.boundedTo(container->maximumSize()));
// make sure the widget fits on screen
//.........这里部分代码省略.........