您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ visualRect函数代码示例

51自学网 2021-06-03 09:43:14
  C++
这篇教程C++ visualRect函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中visualRect函数的典型用法代码示例。如果您正苦于以下问题:C++ visualRect函数的具体用法?C++ visualRect怎么用?C++ visualRect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了visualRect函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: indexAt

	void ItemListView::dragMoveEvent(QDragMoveEvent *event)	{		QModelIndex index = indexAt(event->pos());		bool afterLastItem = false;		if(index.isValid())		{			mDropIndicator = visualRect(index);			if(event->pos().y() > mDropIndicator.top() + mDropIndicator.height() / 2)			{				index = model()->index(index.row() + 1, 0, QModelIndex());				if(index.isValid())					mDropIndicator = visualRect(index);				else					afterLastItem = true;			}		}		else			afterLastItem = true;		if(afterLastItem)		{			index = model()->index(model()->rowCount() - 1, 0, QModelIndex());			mDropIndicator = visualRect(index);			mDropIndicator = mDropIndicator.translated(0, mDropIndicator.height());		}		QListView::dragMoveEvent(event);	}
开发者ID:Danielweber7624,项目名称:actiona,代码行数:30,


示例2: currentIndex

void ThumbnailView::rowsAboutToBeRemoved( const QModelIndex &parent, int start, int end ){    QModelIndex index = currentIndex();    QScrollBar *vScroll = verticalScrollBar();    int startY = visualRect( index.sibling( start, index.column() ) ).top();    int endY = visualRect( index.sibling( end + 1, index.column() ) ).top();    int scrollValue = vScroll->value() - endY + startY;    QListView::rowsAboutToBeRemoved( parent, start, end );    if( index.row() >= start )    {        if( index.row() <= end && end + 1 < model()->rowCount( parent ) )        {            selectionModel()->setCurrentIndex(                    model()->index( end + 1, index.column(), parent ),                    QItemSelectionModel::ClearAndSelect);        }    }    if( startY <= 0 )        vScroll->setValue( scrollValue );}
开发者ID:Camelek,项目名称:qtmoko,代码行数:26,


示例3: visualRect

void TracksView::keepVisible(const QModelIndex &previous, const QModelIndex &current)      {      // update scroll bars to show the cell hidden by the frozen table view if it gets focus      const int hInvisibleGap = visualRect(current).topLeft().x() - frozenVTableWidth();      const int vInvisibleGap = visualRect(current).topLeft().y() - frozenHTableHeight();      if (current.column() != previous.column() && current.column() >= _frozenColCount                  && hInvisibleGap < 0) {            const int newValue = horizontalScrollBar()->value() + hInvisibleGap;            horizontalScrollBar()->setValue(newValue);            }      if (current.row() != previous.row() && current.row() >= _frozenRowCount                  && vInvisibleGap < 0) {            const int newValue = verticalScrollBar()->value() + vInvisibleGap;            verticalScrollBar()->setValue(newValue);            }      // update scroll bars to show the cell hidden by the borders of main table view      const int hInvisibleGap2 = width() - verticalHeader()->width() - 4 * frameWidth()                  - ((verticalScrollBar()->isHidden()) ? 0 : verticalScrollBar()->width())                  - visualRect(current).bottomRight().x();      const int vInvisibleGap2 = height() - horizontalHeader()->height() - 4 * frameWidth()                  - ((horizontalScrollBar()->isHidden()) ? 0 : horizontalScrollBar()->height())                  - visualRect(current).bottomRight().y();      if (current.column() != previous.column() && hInvisibleGap2 < 0) {            const int newValue = horizontalScrollBar()->value() - hInvisibleGap2;            horizontalScrollBar()->setValue(newValue);            }      if (current.row() != previous.row() && vInvisibleGap2 < 0) {            const int newValue = verticalScrollBar()->value() - vInvisibleGap2;            verticalScrollBar()->setValue(newValue);            }      }
开发者ID:AdrianShe,项目名称:MuseScore,代码行数:34,


示例4: switch

void KNMusicTreeViewBase::keyReleaseEvent(QKeyEvent *event){    QRect selectedRect;    //Get the key event    switch(event->key())    {    case Qt::Key_Menu:        //Hide preview tooltips.        KNMusicGlobal::detailTooltip()->hide();        //Check the select rows count.        switch(selectionModel()->selectedRows().size())        {        case 0:            break;        case 1:            //Calculate the selected rows position.            selectedRect=visualRect(currentIndex());            showSoloMenu(QPoint(0,                                selectedRect.y()));            break;        default:            //Calculate the selected rows position.            selectedRect=visualRect(currentIndex());            showMultiMenu(QPoint(0,                                 selectedRect.y()));            break;        }    default:        QTreeView::keyReleaseEvent(event);        break;    }}
开发者ID:AG3,项目名称:Mu,代码行数:32,


示例5: pixelMetric

QRect QMdStyle::subControlRect(ComplexControl whichControl,                                  const QStyleOptionComplex *option,                                  SubControl whichSubControl,                                  const QWidget *widget) const{    if (whichControl == CC_SpinBox) {        int frameWidth = pixelMetric(PM_DefaultFrameWidth, option,                                     widget);        int buttonWidth = 40;        switch (whichSubControl) {        case SC_SpinBoxFrame:            return option->rect;        case SC_SpinBoxEditField:            return option->rect.adjusted(+buttonWidth, +frameWidth,                                         -buttonWidth, -frameWidth);        case SC_SpinBoxDown:            return visualRect(option->direction, option->rect,                              QRect(option->rect.x(), option->rect.y(),                                    buttonWidth,                                    option->rect.height()));        case SC_SpinBoxUp:            return visualRect(option->direction, option->rect,                              QRect(option->rect.right() - buttonWidth,                                    option->rect.y(),                                    buttonWidth,                                    option->rect.height()));        default:            return QRect();        }    } else {        return QWindowsStyle::subControlRect(whichControl, option,                                             whichSubControl, widget);    }}
开发者ID:httpftpli,项目名称:mdimh,代码行数:35,


示例6: setCurrentIndex

void KNMusicAlbumView::selectAlbum(const QModelIndex &albumIndex){    //If the index is vaild, set the initial animation parameters.    if(albumIndex.isValid())    {        //Check whether the album index is the same as the current one.        if(albumIndex==m_selectedIndex)        {            //We don't need to expand the same album.            return;        }        //Set current index to the proxy index of the album index.        setCurrentIndex(m_proxyModel->mapFromSource(albumIndex));        //Set the selected index.        m_selectedIndex=albumIndex;        //Show the detail.        m_albumDetail->setAnimeParameter(                    visualRect(m_proxyModel->mapFromSource(m_selectedIndex)),                    m_itemWidth);        m_albumDetail->displayAlbumDetail(m_selectedIndex);        //Update the album view.        viewport()->update();        //Finished.        return;    }    //Show the detail.    m_albumDetail->setAnimeParameter(                visualRect(m_proxyModel->mapFromSource(m_selectedIndex)),                m_itemWidth);    //Do fold detail animation.    m_albumDetail->foldAlbumDetail();    //Update the viewport.    update();    viewport()->update();}
开发者ID:delkyd,项目名称:Mu,代码行数:35,


示例7: isThumbVisible

bool ThumbView::isThumbVisible(QModelIndex idx){	if (viewport()->rect().contains(QPoint(0, visualRect(idx).y() + visualRect(idx).height() + 1))) {		return true;	}	return false;}
开发者ID:JHooverman,项目名称:phototonic,代码行数:8,


示例8: selectedIndexes

/** * QT 4.7.1 拖拽的函数默认调用过程: * * Model.supportedDropActions() * * View.startDrag() *     Model.mimeData() // 获取拖拽数据 *     Model.supportedDragActions() *         Model.supportedDropActions() *     QDrag.exec() // 阻塞,直到拖拽结束 * *         // 在拖拽过程中,如果拖拽进入某个节点 *         View.dragEnterEvent() // 默认实现会拒绝拖拽,需要重写并调用 QDragEnterEvent.acceptProposedAction() *             Model.mimeTypes() *         View.dragMoveEvent() *             Model.mimeTypes() *         View.dragLeaveEvent() * *         // 拖拽结束后 *         View.dropEvent() *             Model.dropMimeData() // QT用来接收数据 * *     // exec()执行完后,如果是 MoveAction,则调用 *     Model.removeSelectedRows() // QT用来删除数据 * * 上述默认过程对跨 View 拖放支持不好, 下面的startDrag()函数摘自默认实现,并 * 将部分代码替换掉以免调用removeSelectedRows()函数 */void DirectoryTree::startDrag(Qt::DropActions){    const QModelIndexList indexes = selectedIndexes();    if (indexes.count() == 0)        return;    // setup pixmap    QRect rect = visualRect(indexes.at(0));    QList<QRect> rects;    for (size_t i = 0, s = indexes.count(); i < s; ++i)    {        rects.append(visualRect(indexes.at(i)));        rect |= rects.at(i);    }    rect = rect.intersected(viewport()->rect());    QPixmap pixmap(rect.size());    pixmap.fill(palette().base().color());    QPainter painter(&pixmap);    QStyleOptionViewItem option = viewOptions();    option.state |= QStyle::State_Selected;    for (size_t j = 0, s = indexes.count(); j < s; ++j)    {        option.rect = QRect(rects.at(j).topLeft() - rect.topLeft(),        rects.at(j).size());        itemDelegate()->paint(&painter, option, indexes.at(j));    }    painter.end();    // create drag object    QDrag *drag = new QDrag(this);    drag->setPixmap(pixmap);    drag->setMimeData(model()->mimeData(indexes));    drag->setHotSpot(viewport()->mapFromGlobal(QCursor::pos()) - rect.topLeft());    /**     * 在拖动之前,先把 parent 和  row 保存下来,     * 在 Model.dropMimeData() 中统一进行底层数据和视图层数据的修改,     * 避免索引混乱     */    DirectoryTreeModel *m = (DirectoryTreeModel*) model();    QModelIndex parent = indexes.at(0).parent();    int row = indexes.at(0).row();    m->prepare_draging_drop(parent, row);    /*     * 这里的原来的实现 removeSelectedRows() 是我们不需要的, 且 QDrag->start() 总是允许 Qt::CopyAction     * 而我们需要的是,内部用 Qt::MoveAction,外部用 Qt::CopyAction且内部不支持 Qt::CopyAction且内部不支持     * Qt::CopyAction,否则导致错误     *    if (drag->start(supportedActions) == Qt::MoveAction)        removeSelectedRows();    */    drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::MoveAction);}
开发者ID:jingqi,项目名称:organic,代码行数:82,


示例9: visualRect

QModelIndex QFrozenRowTableWidget::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers){      QModelIndex current = QTableWidget::moveCursor(cursorAction, modifiers);      if (cursorAction == MoveLeft && current.column() > 0              && visualRect(current).topLeft().x() < frozenTableWidget->rowHeight(0) ){            const int newValue = verticalScrollBar()->value() + visualRect(current).topLeft().x()                                 - frozenTableWidget->rowHeight(0);            verticalScrollBar()->setValue(newValue);      }      return current;}
开发者ID:ifaoe,项目名称:daisi-gui,代码行数:12,


示例10: getLastVisibleThumb

int ThumbView::getLastVisibleThumb(){	QModelIndex idx;	for (int currThumb = thumbViewModel->rowCount() -1; currThumb >= 0 ; --currThumb) {		idx = thumbViewModel->indexFromItem(thumbViewModel->item(currThumb));		if (viewport()->rect().contains(QPoint(0, visualRect(idx).y() + visualRect(idx).height() + 1))) {			return idx.row();		}	}	return -1;}
开发者ID:JHooverman,项目名称:phototonic,代码行数:13,


示例11: visualRect

//! [navigate]QModelIndex FreezeTableWidget::moveCursor(CursorAction cursorAction,                                          Qt::KeyboardModifiers modifiers){      QModelIndex current = QTableView::moveCursor(cursorAction, modifiers);      if (cursorAction == MoveLeft && current.column() > 0              && visualRect(current).topLeft().x() < frozenTableView->columnWidth(0) ){            const int newValue = horizontalScrollBar()->value() + visualRect(current).topLeft().x()                                 - frozenTableView->columnWidth(0);            horizontalScrollBar()->setValue(newValue);      }      return current;}
开发者ID:SchleunigerAG,项目名称:WinEC7_Qt5.3.1_Fixes,代码行数:14,


示例12: selectedIndexes

void ItemList::startDrag(Qt::DropActions supportedActions){    const QModelIndexList indexes = selectedIndexes();    if (indexes.count() == 0)        return;    // setup pixmap    QRect rect = visualRect(indexes.at(0));    QList<QRect> rects;    for (size_t i = 0, s = indexes.count(); i < s; ++i)    {        rects.append(visualRect(indexes.at(i)));        rect |= rects.at(i);    }    rect = rect.intersected(viewport()->rect());    QPixmap pixmap(rect.size());    pixmap.fill(palette().base().color());    QPainter painter(&pixmap);    QStyleOptionViewItem option = viewOptions();    option.state |= QStyle::State_Selected;    for (size_t j = 0, s = indexes.count(); j < s; ++j)    {        option.rect = QRect(rects.at(j).topLeft() - rect.topLeft(),        rects.at(j).size());        itemDelegate()->paint(&painter, option, indexes.at(j));    }    painter.end();    // create drag object    QDrag *drag = new QDrag(this);    drag->setPixmap(pixmap);    drag->setMimeData(model()->mimeData(indexes));    drag->setHotSpot(viewport()->mapFromGlobal(QCursor::pos()) - rect.topLeft());    /*     * 这里的原来的实现被注释掉    if (drag->start(supportedActions) == Qt::MoveAction)        removeSelectedRows();    */    ItemListModel *m = dynamic_cast<ItemListModel*>(model());    assert(NULL != m); /// QAbstractItemModel::supportedDragActions()居然不是虚函数,我C了!!!    Qt::DropAction rs = drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::MoveAction);    if (rs == Qt::MoveAction)    {        assert(indexes.count() != 0);        m->_remove_after_drag(indexes.at(0).row());    }}
开发者ID:jingqi,项目名称:organic,代码行数:48,


示例13: viewport

void PieView::scrollTo(const QModelIndex &index, ScrollHint){    QRect area = viewport()->rect();    QRect rect = visualRect(index);    if (rect.left() < area.left()) {        horizontalScrollBar()->setValue(            horizontalScrollBar()->value() + rect.left() - area.left());    } else if (rect.right() > area.right()) {        horizontalScrollBar()->setValue(            horizontalScrollBar()->value() + qMin(                rect.right() - area.right(), rect.left() - area.left()));    }    if (rect.top() < area.top()) {        verticalScrollBar()->setValue(            verticalScrollBar()->value() + rect.top() - area.top());    } else if (rect.bottom() > area.bottom()) {        verticalScrollBar()->setValue(            verticalScrollBar()->value() + qMin(                rect.bottom() - area.bottom(), rect.top() - area.top()));    }    update();}
开发者ID:SchleunigerAG,项目名称:WinEC7_Qt5.3.1_Fixes,代码行数:25,


示例14: visualRect

QModelIndex FolderViewListView::indexAt(const QPoint& point) const {  QModelIndex index = QListView::indexAt(point);  // NOTE: QListView has a severe design flaw here. It does hit-testing based on the   // total bound rect of the item. The width of an item is determined by max(icon_width, text_width).  // So if the text label is much wider than the icon, when you click outside the icon but  // the point is still within the outer bound rect, the item is still selected.  // This results in very poor usability. Let's do precise hit-testing here.  // An item is hit only when the point is in the icon or text label.  // If the point is in the bound rectangle but outside the icon or text, it should not be selected.  if(viewMode() == QListView::IconMode && index.isValid()) {    // FIXME: this hack only improves the usability partially. We still need more precise sizeHint handling.    // FolderItemDelegate* delegate = static_cast<FolderItemDelegate*>(itemDelegateForColumn(FolderModel::ColumnFileName));    // Q_ASSERT(delegate != NULL);    // We use the grid size - (2, 2) as the size of the bounding rectangle of the whole item.    // The width of the text label hence is gridSize.width - 2, and the width and height of the icon is from iconSize().    QRect visRect = visualRect(index); // visibal area on the screen    QSize itemSize = gridSize();    itemSize.setWidth(itemSize.width() - 2);    itemSize.setHeight(itemSize.height() - 2);    QSize _iconSize = iconSize();    int textHeight = itemSize.height() - _iconSize.height();    if(point.y() < visRect.bottom() - textHeight) {      // the point is in the icon area, not over the text label      int iconXMargin = (itemSize.width() - _iconSize.width()) / 2;      if(point.x() < (visRect.left() + iconXMargin) || point.x() > (visRect.right() - iconXMargin))	return QModelIndex();    }    // qDebug() << "visualRect: " << visRect << "point:" << point;  }  return index;}
开发者ID:crashd,项目名称:pcmanfm-qt,代码行数:31,


示例15: indexAt

void ColumnDropCSVView::mousePressEvent(QMouseEvent *press){	QModelIndex atClick = indexAt(press->pos());	if (!atClick.isValid() || atClick.row())		return;	QRect indexRect = visualRect(atClick);	QPixmap pix(indexRect.width(), indexRect.height());	pix.fill(QColor(0,0,0,0));	render(&pix, QPoint(0, 0),QRegion(indexRect));	QDrag *drag = new QDrag(this);	QMimeData *mimeData = new QMimeData;	mimeData->setData(subsurface_mimedata, atClick.data().toByteArray());	mimeData->setData(subsurface_index, QString::number(atClick.column()).toUtf8());	drag->setPixmap(pix);	drag->setMimeData(mimeData);	if (drag->exec() != Qt::IgnoreAction){		QObject *target = drag->target();		if (target->objectName() ==  "qt_scrollarea_viewport")			target = target->parent();		if (target != drag->source())			model()->setData(atClick, QString());	}}
开发者ID:torvalds,项目名称:subsurface,代码行数:25,


示例16: indexAt

void QmlConsoleView::mousePressEvent(QMouseEvent *event){    QPoint pos = event->pos();    QModelIndex index = indexAt(pos);    if (index.isValid()) {        ConsoleItem::ItemType type = (ConsoleItem::ItemType)index.data(                    QmlConsoleItemModel::TypeRole).toInt();        bool handled = false;        if (type == ConsoleItem::UndefinedType) {            bool showTypeIcon = index.parent() == QModelIndex();            ConsoleItemPositions positions(visualRect(index), viewOptions().font, showTypeIcon,                                           true);            if (positions.expandCollapseIcon().contains(pos)) {                if (isExpanded(index))                    setExpanded(index, false);                else                    setExpanded(index, true);                handled = true;            }        }        if (!handled)            Utils::TreeView::mousePressEvent(event);    } else {        selectionModel()->setCurrentIndex(model()->index(model()->rowCount() - 1, 0),                                          QItemSelectionModel::ClearAndSelect);    }}
开发者ID:FlavioFalcao,项目名称:qt-creator,代码行数:28,


示例17: indexAt

void PlaylistView::mousePressEvent(QMouseEvent* event) {  if (!(editTriggers() & QAbstractItemView::SelectedClicked)) {    QTreeView::mousePressEvent(event);    return;  }  QModelIndex index = indexAt(event->pos());  if (event->button() == Qt::LeftButton && index.isValid() &&      index.data(Playlist::Role_CanSetRating).toBool()) {    // Calculate which star was clicked    double new_rating =        RatingPainter::RatingForPos(event->pos(), visualRect(index));    if (selectedIndexes().contains(index)) {      // Update all the selected items      QModelIndexList src_index_list;      for (const QModelIndex& index : selectedIndexes()) {        if (index.data(Playlist::Role_CanSetRating).toBool()) {          QModelIndex src_index = playlist_->proxy()->mapToSource(index);          src_index_list << src_index;        }      }      playlist_->RateSongs(src_index_list, new_rating);    } else {      // Update only this item      playlist_->RateSong(playlist_->proxy()->mapToSource(index), new_rating);    }  } else {    QTreeView::mousePressEvent(event);  }  inhibit_autoscroll_ = true;  inhibit_autoscroll_timer_->start();}
开发者ID:Gu1,项目名称:Clementine,代码行数:34,


示例18: visualRect

void HoverableTreeView::drawRow(QPainter* painter, const QStyleOptionViewItem& options, const QModelIndex& index) const{    HoverableStyleOptionViewItem opt = options;    QRect r = visualRect(index).adjusted(0, 1, 0, 1);    r.setLeft(0);    opt.decorationSize = QSize();    if (underMouse() &&        !mousePosition_.isNull() &&        r.contains(mousePosition_) &&        !verticalScrollBar()->underMouse() &&        !verticalScrollBar()->isSliderDown())    {        // we're hacking our way through the QTreeView which casts HoverableStyleOptionViewItem        // down to HoverableStyleOptionViewItemBaseClass and loses the hovered flag        opt.displayAlignment = Qt::AlignLeft | Qt::AlignRight | Qt::AlignHCenter | Qt::AlignJustify;        // decorationSize will hold the mouse coordinates starting from opt.rect.topLeft()        QPoint offset = mousePosition_ /*- QPoint(opt.rect.left(), 0)*/;        opt.decorationSize = QSize(offset.x(), offset.y());        opt.hovered = true;        opt.hoveredPosition = QPoint(offset.x(), offset.y());    }    QTreeView::drawRow(painter, opt, index);}
开发者ID:psi-im,项目名称:psi,代码行数:27,


示例19: viewport

//-----------------------------------------------------------------------------void vktraceviewer_QTimelineView::scrollTo(const QModelIndex &index, ScrollHint hint/* = EnsureVisible*/){    if (!index.isValid())    {        return;    }    QRect viewRect = viewport()->rect();    QRect itemRect = visualRect(index);    if (itemRect.left() < viewRect.left())    {        horizontalScrollBar()->setValue(horizontalScrollBar()->value() + itemRect.center().x() - viewport()->width()/2);    }    else if (itemRect.right() > viewRect.right())    {        horizontalScrollBar()->setValue(horizontalScrollBar()->value() + itemRect.center().x() - viewport()->width()/2);    }    if (!viewRect.contains(itemRect))    {        deletePixmap();    }    viewport()->update();}
开发者ID:LunarG,项目名称:VulkanTools,代码行数:26,


示例20: viewport

bool EventsListView::viewportEvent(QEvent *event){    if (event->type() != QEvent::ToolTip && event->type() != QEvent::WhatsThis) {        return QListView::viewportEvent(event);    }    QPoint global_pos = QCursor::pos();    QPoint viewport_pos = viewport()->mapFromGlobal(global_pos);    QModelIndex index = indexAt(viewport_pos);    if (!index.isValid()) {        return true;    }    EventItem *item = getItem(index);    if (!item) {        return true;    }    QRect item_rect = visualRect(index);    QString text = "<p style='white-space:pre'>";    text += item->event().desc;    text += "</p>";    QToolTip::showText(QCursor::pos(), text, viewport(), item_rect);    return true;}
开发者ID:haiwen,项目名称:seafile-client,代码行数:28,


示例21: viewport

bool RepoTreeView::viewportEvent(QEvent *event){    if (event->type() != QEvent::ToolTip && event->type() != QEvent::WhatsThis) {        return QTreeView::viewportEvent(event);    }    QPoint global_pos = QCursor::pos();    QPoint viewport_pos = viewport()->mapFromGlobal(global_pos);    QModelIndex index = indexAt(viewport_pos);    if (!index.isValid()) {        return true;    }    QStandardItem *item = getRepoItem(index);    if (!item) {        return true;    }    QRect item_rect = visualRect(index);    if (item->type() == REPO_ITEM_TYPE) {        showRepoItemToolTip((RepoItem *)item, global_pos, item_rect);    } else {        showRepoCategoryItemToolTip((RepoCategoryItem *)item, global_pos, item_rect);    }    return true;}
开发者ID:xudaiqing,项目名称:seafile-client,代码行数:27,


示例22: selectedIndexes

void TreeView::startDrag(Qt::DropActions supportedActions){	QModelIndex index = selectedIndexes().value(0);	if (!index.isValid())		return;	QMimeData *data = model()->mimeData(QModelIndexList() << index);	if (!data)		return;	QRect rect;	QPixmap pixmap;	QPoint point;	{		QAbstractItemDelegate *delegate = itemDelegate(index);		QStyleOptionViewItemV4 option = viewOptions();		option.locale = this->locale();		option.locale.setNumberOptions(QLocale::OmitGroupSeparator);		option.widget = this;		option.state |= QStyle::State_Selected;		option.rect = visualRect(index);		point = option.rect.topLeft();		option.rect.moveTo(0, 0);		option.rect.setSize(delegate->sizeHint(option, index));		rect = option.rect;		pixmap = QPixmap(rect.size());		pixmap.fill(Qt::transparent);		QPainter painter(&pixmap);		delegate->paint(&painter, option, index);	}	QDrag *drag = new QDrag(this);	drag->setPixmap(pixmap);	drag->setMimeData(data);	point = QCursor::pos() - viewport()->mapToGlobal(point);	drag->setHotSpot(point);	//			drag->setHotSpot(QCursor::pos() - rect.topLeft());	Qt::DropAction setDefaultDropAction = QAbstractItemView::defaultDropAction();	Qt::DropAction defaultDropAction = Qt::IgnoreAction;	if (setDefaultDropAction != Qt::IgnoreAction && (supportedActions & setDefaultDropAction))		defaultDropAction = setDefaultDropAction;	else if (supportedActions & Qt::CopyAction && dragDropMode() != QAbstractItemView::InternalMove)		defaultDropAction = Qt::CopyAction;	if (drag->exec(supportedActions, defaultDropAction) == Qt::IgnoreAction			&& index.data(ItemTypeRole).toInt() == ContactType) {		if (QWidget *widget = QApplication::topLevelAt(QCursor::pos())) {			if (widget->window() == this->window())				return;		}		Event ev("contact-list-drop",				 QCursor::pos() - point,				 index.data(BuddyRole));		ev.send();	}	//			debug() << "DropAction" << drag->exec(supportedActions, defaultDropAction);	//			if (drag->exec(supportedActions, defaultDropAction) == Qt::MoveAction)	//				d->clearOrRemove();	//			{}}
开发者ID:andrecurvello,项目名称:qutim,代码行数:59,


示例23: scrollToRelaxed

void ItemViewCategorized::scrollToRelaxed(const QModelIndex& index, QAbstractItemView::ScrollHint hint){    if (viewport()->rect().intersects(visualRect(index)))    {        return;    }    scrollTo(index, hint);}
开发者ID:KDE,项目名称:digikam,代码行数:9,


示例24: ensurePolished

int CustomTreeView::sizeHintForColumn(int col) const {  if (!model() || col > 0)    return -1;  ensurePolished();  int hint = 0;  QModelIndex index = model()->index(0,col);  while (index.isValid()) {    if (viewport()->rect().contains(visualRect(index))) {      hint = qMax(hint, visualRect(index).x() + itemDelegate(index)->sizeHint(viewOptions(), index).width());    }    index = indexBelow(index);  }  return qMin(hint, viewport()->rect().width());}
开发者ID:vadivelselvaraj,项目名称:TulipGLImprovement,代码行数:18,


示例25: indexAt

void TTreeWidget::mousePressEvent( QMouseEvent *event ){    QModelIndex indexClicked = indexAt(event->pos());    if( mIsVarTree && indexClicked.isValid() )    {        QRect vrect = visualRect(indexClicked);        int itemIndentation = vrect.x() - visualRect(rootIndex()).x();        QRect rect = QRect(header()->sectionViewportPosition(0) + itemIndentation,                           vrect.y(), style()->pixelMetric(QStyle::PM_IndicatorWidth), vrect.height());        if(rect.contains(event->pos()))        {            mClickedItem = indexClicked;            QTreeWidget::mousePressEvent(event);            return;        }    }    QTreeWidget::mousePressEvent(event);}
开发者ID:Akivaii,项目名称:Mudlet,代码行数:18,


示例26: indexAt

/** * This function is used to create custom behaviour when clicking * on user/channel flags (e.g. showing the comment) */void UserView::mouseReleaseEvent(QMouseEvent *evt) {	QPoint qpos = evt->pos();	QModelIndex idx = indexAt(qpos);	if ((evt->button() == Qt::LeftButton) && idx.isValid()) {		UserModel *um = static_cast<UserModel *>(model());		ClientUser *cu = um->getUser(idx);		Channel * c = um->getChannel(idx);		if ((cu && ! cu->qbaCommentHash.isEmpty()) ||		        (! cu && c && ! c->qbaDescHash.isEmpty())) {			QRect r = visualRect(idx);			int offset = 18;			if (cu) {				// Calculate pixel offset of comment flag				if (cu->bLocalIgnore)					offset += 18;				if (cu->bRecording)					offset += 18;				if (cu->bPrioritySpeaker)					offset += 18;				if (cu->bMute)					offset += 18;				if (cu->bSuppress)					offset += 18;				if (cu->bSelfMute)					offset += 18;				if (cu->bLocalMute)					offset += 18;				if (cu->bSelfDeaf)					offset += 18;				if (cu->bDeaf)					offset += 18;				if (! cu->qsFriendName.isEmpty())					offset += 18;				if (cu->iId >= 0)					offset += 18;			}			offset = r.topRight().x() - offset;			if ((qpos.x() >= offset) && (qpos.x() <= (offset+18))) {				QString str = um->data(idx, Qt::ToolTipRole).toString();				if (str.isEmpty()) {					um->bClicked = true;				} else {					QWhatsThis::showText(viewport()->mapToGlobal(r.bottomRight()), str, this);					um->seenComment(idx);				}				return;			}		}	}	QTreeView::mouseReleaseEvent(evt);}
开发者ID:Durlockozk,项目名称:mumble,代码行数:60,


示例27: qCDebug

bool AlbumSelectionTreeView::viewportEvent(QEvent* event){    // let the base class handle the event if it is not a tool tip request    if (event->type() != QEvent::ToolTip)    {        return AlbumTreeView::viewportEvent(event);    }    // only show tool tips if requested    if (!d->enableToolTips)    {        return false;    }    // check that we got a correct event    QHelpEvent* const helpEvent = dynamic_cast<QHelpEvent*> (event);    if (!helpEvent)    {        qCDebug(DIGIKAM_GENERAL_LOG) << "Unable to determine the correct type of the event. "                 << "This should not happen.";        return false;    }    // find the item this tool tip belongs to    QModelIndex index = indexAt(helpEvent->pos());    if (!index.isValid())    {        return true;    }    PAlbum* const album = albumForIndex(index);    if (!album || album->isRoot() || album->isAlbumRoot())    {        // there was no album so we really don't want to show a tooltip.        return true;    }    QRect itemRect = visualRect(index);    if (!itemRect.contains(helpEvent->pos()))    {        return true;    }    QStyleOptionViewItem option = viewOptions();    option.rect                 = itemRect;    // visualRect can be larger than viewport, intersect with viewport rect    option.rect                 &= viewport()->rect();    option.state                |= (index == currentIndex() ? QStyle::State_HasFocus : QStyle::State_None);    d->toolTip->show(option, index);    return true;}
开发者ID:Match-Yang,项目名称:digikam,代码行数:56,


示例28: indexAt

void WinBarGroup::mousePressEvent(QMouseEvent *event){    QModelIndex index = indexAt(event->pos());    if(event->button() == Qt::LeftButton && index.isValid()){       m_rect = visualRect(index);        m_pressed = true;        update(index);    }    QTableView::mousePressEvent(event);}
开发者ID:chrismayo,项目名称:ONLIGHT,代码行数:10,


示例29: indexAt

bool BaseFinderView::isHoveringPlayIcon(QMouseEvent *event) {    const QModelIndex itemIndex = indexAt(event->pos());    const QRect itemRect = visualRect(itemIndex);    // qDebug() << " itemRect.x()" <<  itemRect.x();    const int x = event->x() - itemRect.x();    const int y = event->y() - itemRect.y();    return x > 90 && x < 140 && y > 10 && y < 60;}
开发者ID:junwatu,项目名称:junwatunes,代码行数:10,



注:本文中的visualRect函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ visual_object_unref函数代码示例
C++ visitor函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。