当前位置: 首页>>代码示例>>C++>>正文


C++ QTableView::indexAt方法代码示例

本文整理汇总了C++中QTableView::indexAt方法的典型用法代码示例。如果您正苦于以下问题:C++ QTableView::indexAt方法的具体用法?C++ QTableView::indexAt怎么用?C++ QTableView::indexAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QTableView的用法示例。


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

示例1: eventFilter

bool DataViewer::eventFilter(QObject *watched, QEvent *event)
{
    if (event->type() == QEvent::MouseButtonPress)
    {
        QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
        if (mouseEvent->button() == Qt::RightButton)
        {
            const QPoint globalMousePos = mouseEvent->globalPos();

            QTableView *tableView = d_ptr->m_tableData;
            Q_ASSERT(tableView);

            const QModelIndex tableModelIndex = tableView->indexAt(mouseEvent->pos());
            if (tableModelIndex.isValid())
            {
                QVariant data = tableView->model()->data(tableModelIndex);
                bool ok = false;
                int timestamp = data.toInt(&ok);
                if (ok)
                {
                    QMenu menu;
                    menu.addAction(d_ptr->m_timestampAction);
                    if (menu.exec(globalMousePos))
                    {
                        QMessageBox::information(this, QString(), QDateTime::fromTime_t(timestamp).toString());
                    }
                }
            }
        }
    }

    return BaseViewer::eventFilter(watched, event);
}
开发者ID:sfinae,项目名称:DatabaseBrowser,代码行数:33,代码来源:DataViewer.cpp

示例2: goinBtnPressed

//鼠标点击事件
void ButtonDelegate::goinBtnPressed(QObject *object, QEvent *event){

		QTableView* pView    =   qobject_cast<QTableView*>(object->parent());
		QMouseEvent* pEvent =   static_cast<QMouseEvent*>(event);
		QModelIndex loModelIndex = pView->indexAt(pEvent->pos());

		/*获取model中的数据*/
		int column = loModelIndex.column();
		int row = loModelIndex.row();
		if (row < 0)
		{
			return;
		}
		//int row = loModelIndex.row();
		QVariant varint = loModelIndex.data(Qt::DisplayRole);
		QString str = varint.toString();

		/*获取鼠标点击坐标*/
		/*	int x = pEvent->x();
		int y = pEvent->y();
		int x1 = pEvent->globalX();
		int y2 = pEvent->globalY();
		QPoint  p1 = pEvent->pos();
		QPoint p2 = pEvent->globalPos();
		*/
		PROOM_INFO roomInfo = g_pMeetingFrame->GetRoomInfo(row);
		if(roomInfo==NULL)
			return;
		QString pStr = QString(roomInfo->strPassword);
		int pBool = 0;
		if (pStr.length()>0)
		{
			pBool = 1;
		}else
			pBool = 0;

		QPoint  p1 = pEvent->pos();
		if (p1.x()>350&&p1.x()<405)
		{
			emit sendTableViewNumberRowAndWorth(row,pBool);
		}else
			return;

}
开发者ID:ACEZLY,项目名称:openmeeting2,代码行数:45,代码来源:ButtonDelegate.cpp

示例3: QMainWindow

    OLD_MAIN(QWidget* pParent = nullptr)
        : QMainWindow(pParent)
    {
        Q_INIT_RESOURCE(Resources);

        // Settings persistence
        ReadSettings();

        // Appearance LUT
        PlayerApperances appearances;

        // Build player table model from file
        PlayerTableModel* playerTableModel = new PlayerTableModel(this);
        playerTableModel->LoadHittingProjections(appearances);
        playerTableModel->LoadPitchingProjections(appearances);
        playerTableModel->CalculateHittingScores();
        playerTableModel->CalculatePitchingScores();
        playerTableModel->InitializeTargetValues();

        // Draft delegate
        DraftDelegate* draftDelegate = new DraftDelegate(playerTableModel);
        LinkDelegate* linkDelegate = new LinkDelegate(this);
        TagDelegate* tagDelegate = new TagDelegate(this);

        // Hitter sort-model
        PlayerSortFilterProxyModel* hitterSortFilterProxyModel = new PlayerSortFilterProxyModel(Player::Hitter);
        hitterSortFilterProxyModel->setSourceModel(playerTableModel);
        hitterSortFilterProxyModel->setSortRole(PlayerTableModel::RawDataRole);

        // Hitter table view
        QTableView* hitterTableView = MakeTableView(hitterSortFilterProxyModel, true, PlayerTableModel::COLUMN_Z);
        hitterTableView->setItemDelegateForColumn(FindColumn(hitterSortFilterProxyModel, PlayerTableModel::COLUMN_DRAFT_BUTTON), draftDelegate);
        hitterTableView->setItemDelegateForColumn(FindColumn(hitterSortFilterProxyModel, PlayerTableModel::COLUMN_ID_LINK), linkDelegate);
        hitterTableView->setItemDelegateForColumn(FindColumn(hitterSortFilterProxyModel, PlayerTableModel::COLUMN_FLAG), tagDelegate);
        hitterTableView->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked);

        // Context menu
        QMenu* contextMenu = new QMenu();
        contextMenu->addAction("&Remove Player");

        // Apply to hitter table view
        hitterTableView->setContextMenuPolicy(Qt::CustomContextMenu);
        connect(hitterTableView, &QWidget::customContextMenuRequested, [=](const QPoint& pos) {
            QPoint globalPos = hitterTableView->mapToGlobal(pos);
            QAction* selectedItem = contextMenu->exec(globalPos);
            if (selectedItem) {
                auto proxyIndex = hitterTableView->indexAt(pos);
                auto srcIndex = hitterSortFilterProxyModel->mapToSource(proxyIndex);
                playerTableModel->RemovePlayer(srcIndex.row());
            }
        });

        // Pitcher sort-model
        PlayerSortFilterProxyModel* pitcherSortFilterProxyModel = new PlayerSortFilterProxyModel(Player::Pitcher);
        pitcherSortFilterProxyModel->setSourceModel(playerTableModel);
        pitcherSortFilterProxyModel->setSortRole(PlayerTableModel::RawDataRole);
        
        // Pitcher table view
        QTableView* pitcherTableView = MakeTableView(pitcherSortFilterProxyModel, true, PlayerTableModel::COLUMN_Z);
        pitcherTableView->setItemDelegateForColumn(FindColumn(pitcherSortFilterProxyModel, PlayerTableModel::COLUMN_DRAFT_BUTTON), draftDelegate);
        pitcherTableView->setItemDelegateForColumn(FindColumn(pitcherSortFilterProxyModel, PlayerTableModel::COLUMN_ID_LINK), linkDelegate);
        pitcherTableView->setItemDelegateForColumn(FindColumn(pitcherSortFilterProxyModel, PlayerTableModel::COLUMN_FLAG), tagDelegate);
        pitcherTableView->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked);

        // Top/Bottom splitter
        QSplitter* topBottomSplitter = new QSplitter(Qt::Vertical);
        topBottomSplitter->setContentsMargins(5, 5, 5, 5);

        // Hitter/Pitcher tab View
        enum PlayerTableTabs { Hitters, Pitchers, Unknown };
        QTabWidget* hitterPitcherTabs = new QTabWidget(this);
        hitterPitcherTabs->insertTab(PlayerTableTabs::Hitters, hitterTableView, "Hitters");
        hitterPitcherTabs->insertTab(PlayerTableTabs::Pitchers, pitcherTableView, "Pitchers");
        topBottomSplitter->addWidget(hitterPitcherTabs);

        // Tab lookup helper
        auto CaterogyToTab = [](uint32_t catergory) 
        {
            switch (catergory)
            {
            case Player::Hitter:
                return PlayerTableTabs::Hitters;
            case Player::Pitcher:
                return PlayerTableTabs::Pitchers;
            default:
                return PlayerTableTabs::Unknown;
            }
        };

        // Drafted filter action
        QAction* filterDrafted = new QAction(this);
        connect(filterDrafted, &QAction::toggled, hitterSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterDrafted);
        connect(filterDrafted, &QAction::toggled, pitcherSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterDrafted);
        filterDrafted->setText(tr("Drafted"));
        filterDrafted->setToolTip("Toggle Drafted Players");
        filterDrafted->setCheckable(true);
        filterDrafted->toggle();

        QAction* filterReplacement = new QAction(this);
        connect(filterReplacement, &QAction::toggled, hitterSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterReplacement);
//.........这里部分代码省略.........
开发者ID:kspagnoli,项目名称:fbb,代码行数:101,代码来源:old_main.cpp


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