首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏全栈程序员必看

    QT 播放器之列表[通俗易懂]

    (const QModelIndex &parent=QModelIndex()) const; QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const; QModelIndex parent(const QModelIndex &child=QModelIndex()) const; createIndex(row,column) :QModelIndex(); } QModelIndex MediaListModel::parent(const QModelIndex (const QModelIndex &parent=QModelIndex()) const; QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const; QModelIndex parent(const QModelIndex &child=QModelIndex()) const;

    2.4K40编辑于 2022-07-01
  • 来自专栏个人编程笔记

    Qt-自定义可编辑模型

    QObject *parent=0); void setCurrencyMap(const QMap<QString,double> &map); int rowCount(const QModelIndex &parent) const; int columnCount(const QModelIndex &parent) const; QVariant data(const QModelIndex section, Qt::Orientation orientation, int role) const; //可编辑模型实现 Qt::ItemFlags flags(const QModelIndex &index)const; bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole &parent) const { return currencyMap.count(); } //返回列数目 int CurrencyModel::columnCount(const QModelIndex

    57410编辑于 2023-03-03
  • C++ Qt开发:QFileSystemModel文件管理组件

    QModelIndex setRootPath(const QString &path) 设置根路径,并返回表示新路径的模型索引。 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const获取模型索引。 QModelIndex parent(const QModelIndex &index) const 获取给定索引的父索引。 int rowCount(const QModelIndex &parent = QModelIndex()) const获取给定父索引下的行数。 int columnCount(const QModelIndex &parent = QModelIndex()) const获取给定父索引下的列数。

    1.9K10编辑于 2024-03-08
  • C++ Qt开发:StringListModel字符串列表映射组件

    QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const 返回指定行、列和父索引的模型索引 QModelIndex parent(const QModelIndex & child) const 返回指定子索引的父索引。 int rowCount(const QModelIndex & parent = QModelIndex()) const 返回给定父索引下的行数。 int columnCount(const QModelIndex & parent = QModelIndex()) const 返回给定父索引下的列数。 bool insertRows(int row, int count, const QModelIndex & parent = QModelIndex()) 在给定父索引下的 row 位置处插入 count

    2K10编辑于 2023-12-22
  • 来自专栏Linux驱动

    25.QT-模型视图

    其中index()是个重载函数,用来获取QModelIndex 索引值,完整的index()函数如下所示: QModelIndex QAbstractItemModel::index ( int row , int column, const QModelIndex & parent = QModelIndex() ); //返回指定的row(行)、column(列)、parent(父索引 ( const QModelIndex & index ) ; //通过索引值获取文件名 QString filePath ( const QModelIndex & index ) ; / const QModelIndex & parent = QModelIndex() ) ; //通过索引值获取当前列数 int rowCount ( const QModelIndex & parent = QModelIndex() ) ; //通过索引值获取行数 QModelIndex parent ( const QModelIndex & index ) ; //通过索引值获取其父节点的索引值

    2.3K20发布于 2018-07-31
  • 来自专栏全栈程序员必看

    《QTreeView+QAbstractItemModel自定义模型》:系列教程之三[通俗易懂]

    QAbstractItemModel类中定义如下: Q_INVOKABLE virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const = 0; Q_INVOKABLE virtual QModelIndex parent(const QModelIndex &child) ; Q_INVOKABLE virtual int rowCount(const QModelIndex &parent = QModelIndex()) const = 0; Q_INVOKABLE QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) const { if (! QModelIndex TreeModel::parent(const QModelIndex &index) const { if (!

    8.7K11编辑于 2022-07-01
  • 来自专栏半生瓜のblog

    【QT】QT模型/视图

    indexA = model.index(0,0,QModelIndex()); qDebug()<<"indexA row count:"<<model.rowCount(indexA); QModelIndex indexB = model.index(0,0,indexA); qDebug()<<"indexB text:"<<model.data(indexB,Qt: )),&list,SLOT(setRootIndex(QModelIndex)) ); QObject::connect(&tree,SIGNAL(doubleClicked(QModelIndex topLeft = m_tableView->model()->index(0,0,QModelIndex()); //右下角模型索引 QModelIndex bottomRight (QModelIndex())-1,QModelIndex()); //项选择 QItemSelection curSelection(topLeft,bottomRight);

    5.2K20编辑于 2023-05-13
  • C/C++ Qt TableDelegate 自定义代理组件

    ; //设置编辑器的数值}void QWIntSpinDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex QWIntSpinDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex QWFloatSpinDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex QWidget *QWComboBoxDelegate::createEditor(QWidget *parent,const QStyleOptionViewItem &option, const QModelIndex QWComboBoxDelegate::updateEditorGeometry(QWidget *editor,const QStyleOptionViewItem &option, const QModelIndex

    1.3K20编辑于 2022-12-23
  • 来自专栏Pou光明

    Qt ModelView教程——设置表头与可编辑Table

    &parent = QModelIndex()) const Q_DECL_OVERRIDE ; int columnCount(const QModelIndex &parent = QModelIndex ()) const Q_DECL_OVERRIDE; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; bool setData(const QModelIndex & index, const QVariant & value, int role = Qt: :EditRole) Q_DECL_OVERRIDE; Qt::ItemFlags flags(const QModelIndex & index) const Q_DECL_OVERRIDE index参数会告诉我们具体哪个单元格被编辑、value参数可以让我们获得单元格内具体的内容 bool MyModel::setData(const QModelIndex & index, const

    4.6K10发布于 2020-02-17
  • 来自专栏个人编程笔记

    Qt-自定义可编辑模型

    QObject *parent=0); void setCurrencyMap(const QMap<QString,double> &map); int rowCount(const QModelIndex &parent) const; int columnCount(const QModelIndex &parent) const; QVariant data(const QModelIndex section, Qt::Orientation orientation, int role) const; //可编辑模型实现 Qt::ItemFlags flags(const QModelIndex &index)const; bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole &parent) const { return currencyMap.count(); } //返回列数目 int CurrencyModel::columnCount(const QModelIndex

    66210编辑于 2023-03-03
  • 来自专栏全栈程序员必看

    Qt树形控件QTreeView使用1——节点的添加删除操作[通俗易懂]

    QModelIndex可以看做是QStandardItem的数据封装,知道 QModelIndex就可以知道QStandardItem,通过QStandardItemModel的 itemFromIndex 函数即可得到QModelIndex对应的QStandardItem。 (int row, int column, const QModelIndex & index) 和 QModelIndex QModelIndex::sibling(int row, int column) const 都可以用于获取兄弟节点信息 例如把 on_treeView_clicked ( const QModelIndex & index )的代码改一下 getTopParent(QModelIndex itemIndex){ QModelIndex secondItem = itemIndex; while(itemIndex.parent

    8.8K30编辑于 2022-09-06
  • 来自专栏技术之路

    QTableView 一列添加两个按钮

    bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex index); signals: public slots: private: void showMsg(QString str); private: typedef QMap<QModelIndex &parent) const; int columnCount(const QModelIndex &parent) const; QVariant data(const QModelIndex &parent) const { return m_data.size(); } int TableModel::columnCount(const QModelIndex &parent) const { return m_HorizontalHeader.count(); } QVariant TableModel::data(const QModelIndex &index

    4.8K90发布于 2018-01-31
  • 来自专栏用户2442861的专栏

    Qt 学习之路 2(45):模型

    int column,                                      const QModelIndex &parent=QModelIndex()) const 这里,我们仅仅使用了前两个参数 因此,我们只需提供两个参数即可获取到表格中的某一个数据项: 1 2 3 QModelIndex indexA = model->index(0, 0, QModelIndex()); QModelIndex indexB = model->index(1, 1, QModelIndex()); QModelIndex indexC = model->index(2, 1, QModelIndex()); 函数的最后一个参数始终是 QModelIndex(),接下来我们就要讨论这个参数的含义。 图中,A 和 C 都是模型中的顶级项: 1 2 QModelIndex indexA = model->index(0, 0, QModelIndex()); QModelIndex indexC

    1.2K20发布于 2018-09-20
  • C++ Qt开发:SqlTableModel映射组件应用

    rowCount(const QModelIndex &parent = QModelIndex()) const 返回模型中的行数。 columnCount(const QModelIndex &parent = QModelIndex()) const返回模型中的列数。 (QModelIndex, QModelIndex)));这个槽函数的实现如下所示,当行被点击后执行获取name/mobile字段,并放入映射数据集中的lineEdit编辑框中,使其能够动态的显示数据列表 QModelIndex() 是一个空的索引,表示插入到末尾。 QModelIndex() 是一个空的索引,表示插入到指定行的上方。

    1.3K00编辑于 2023-12-28
  • C++ Qt开发:SqlTableModel映射组件应用

    rowCount(const QModelIndex &parent = QModelIndex()) const 返回模型中的行数。 columnCount(const QModelIndex &parent = QModelIndex()) const 返回模型中的列数。 record(int row) 返回指定行的记录。 void MainWindow::on_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous) { QModelIndex() 是一个空的索引,表示插入到末尾。 QModelIndex() 是一个空的索引,表示插入到指定行的上方。

    1.2K10编辑于 2023-12-29
  • 来自专栏个人编程笔记

    Qt-使用控件ListView

    model Q_INVOKABLE void clear(); //虚函数 qml内部调用 获取第index行的内容 role 内容索引 QVariant data(const QModelIndex &index, int role =Qt::DisplayRole) const; //虚函数 获取model行数 int rowCount(const QModelIndex &parent = QModelIndex() ) const; // 虚函数 内容的别名 qml 内部调用 //QHash<int, QByteArray> roleNames() const parent) :QAbstractListModel(parent) { } void ToolTagModel::Add(ToolTag& tt) { beginInsertRows(QModelIndex parent) const { Q_UNUSED(parent); return m_datas.size(); } QVariant ToolTagModel::data(const QModelIndex

    1.7K20编辑于 2023-03-03
  • 来自专栏Linux驱动

    26.QT-模型视图之自定义委托

    QAbstractItemDelegate类中的关键虚函数 QWidget * createEditor( QWidget * parent, QStyleOptionViewItem & option, QModelIndex 更新编辑组件大小,保证editor显示的位置及大小 //大小可以通过option.rect获取数据项窗口大小 void setEditorData ( QWidget * editor, const QModelIndex void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) ; / & index ) const ; void setEditorData( QWidget * editor, const QModelIndex & index ) const ; void setModelData( QWidget * editor, QAbstractItemModel * model, const QModelIndex & index

    3K21发布于 2018-07-31
  • 来自专栏用户2442861的专栏

    PyQt QTableView嵌入QComboBox

    ()), QVariant(u'树袋熊')) comboModel.setData(comboModel.index(0, 1, QModelIndex()), QVariant(u'生活在树上的熊 ')) comboModel.setData(comboModel.index(1, 0, QModelIndex()), QVariant(u'松鼠')) comboModel.setData (comboModel.index(1, 1, QModelIndex()), QVariant(u'可爱的松树精灵')) comboModel.setData(comboModel.index(2 , 0, QModelIndex()), QVariant(u'大眼猴')) comboModel.setData(comboModel.index(2, 1, QModelIndex()), QVariant (comboModel.index(3, 1, QModelIndex()), QVariant(u'夜的精灵正站在树枝上')) model = QStandardItemModel(2, 3, table

    2.4K10发布于 2018-09-20
  • 来自专栏全栈程序员必看

    QTreeView使用总结7,右键菜单

    curIndex = ui->treeView->indexAt(pos); //当前点击的元素的index QModelIndex index = curIndex.sibling curIndex = ui->treeView->currentIndex(); QModelIndex index = curIndex.sibling(curIndex.row(),0); curIndex = ui->treeView->currentIndex(); QModelIndex index = curIndex.sibling(curIndex.row(),0); curIndex = ui->treeView->indexAt(pos); //当前点击的元素的index QModelIndex index = curIndex.sibling curIndex = ui->treeView->currentIndex(); QModelIndex index = curIndex.sibling(curIndex.row(),0);

    6.5K50编辑于 2022-08-25
  • 来自专栏Linux驱动

    61.QT-QSortFilterProxyModel代理实现排序、过滤

    : 如果重写了lessThan(),那么就不会再调用model的sort方法了. lessThan()使用示例: bool SortFilterProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const { //通过当前视图中的index位置获取model中实际的数据 QVariant 示例代码如下所示: bool SortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent &source_parent) const override; virtual bool lessThan(const QModelIndex &source_left, const QModelIndex &source_left, const QModelIndex &source_right) const { //通过当前视图中的index位置获取model中实际的数据 QVariant

    7.8K30发布于 2020-12-18
领券