zoukankan      html  css  js  c++  java
  • 如何检测QTableView中是否有选择项

    如何检测QTableView中是否有选择项

    使用QItemSelectionModel类

    QItemSelectionModel类说明:
    The QItemSelectionModel class keeps track of a view's selected items.
    A QItemSelectionModel keeps track of the selected items in a view, or in several views onto the same model. It also keeps 
    
    track of the currently selected item in a view.
    The QItemSelectionModel class is one of the Model/View Classes and is part of Qt's model/view framework.
    QItemSelectionModel类保持与视图选择项之间的联系!
    一个QItemSelectionModel保持着与一个视图(或者同一个model的多个视图)的选择项之间的联系。
    QItemSelectionModel类属于模型-视图类,并且它属于Qt的模型-视图框架的一部分。

    操作:触发QItemSelectionModel的selectionChanged信号,然后在响应槽中通过该类的hasSelection方法判断是否有选择项目。
     可以通过currentIndex获取当前选择项。

    eg.
     QItemSelectionModel * md = ui->tableView->selectionModel();
     connect(md,SIGNAL(selectionChanged(QItemSelection,QItemSelection)),this,SLOT(view_select_check
    
    (QItemSelection,QItemSelection)));
    
     然后在响应槽函数当中:
     if(wordTableSelectionModel->hasSelection())
                ui->selectOk->setEnabled(true);
            else
                ui->selectOk->setDisabled(true);
    至于获取当前选择项,可以使用currentIndex获取当前选择项的QModelIndex,然后进行处理,我这里是投递到它的双击事件中。
     QModelIndex dex = wordTableSelectionModel->currentIndex();
            this->on_tableView_doubleClicked(dex);
  • 相关阅读:
    分布式缓存Redis
    MySQL优化
    SYSRET
    SYSCALL
    bolt cms V3.7.0 xss和远程代码执行漏洞
    github渗透测试工具库
    Gradle系列之Gradle插件
    fastjson 漏洞利用 命令执行
    linux 关闭对端口的监听
    微信小程序自动化测试最佳实践(附 Python 源码)
  • 原文地址:https://www.cnblogs.com/justwake/p/justwake_qitemselectionmodel.html
Copyright © 2011-2022 走看看