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);
  • 相关阅读:
    如何让pc端网站在手机上可以等比缩放的整个显示
    CSS
    常见的IE布局兼容问题
    CSS : 使用 z-index 的前提
    CSS : object-fit 和 object-position实现 图片或视频自适应
    CSS
    vscode
    如何识别Form字段中一对多或者多对多字段
    window.open简单使用
    由一个模型拿它的名字、app的名字、字段对象以及字段对象中的属性
  • 原文地址:https://www.cnblogs.com/justwake/p/justwake_qitemselectionmodel.html
Copyright © 2011-2022 走看看