求助QlistView-CSDN论坛

求助QlistView-CSDN论坛,第1张

void QAbstractItemView::setModel(QAbstractItemModel model)

{

    Q_D(QAbstractItemView);

    if (model == d->model)

        return;

    if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) {

        disconnect(d->model, SIGNAL(destroyed()),

                   this, SLOT(_q_modelDestroyed()));

        disconnect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),

                   this, SLOT(dataChanged(QModelIndex,QModelIndex)));

        disconnect(d->model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),

                   this, SLOT(_q_headerDataChanged()));

        disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),

                   this, SLOT(rowsInserted(QModelIndex,int,int)));

        disconnect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),

                   this, SLOT(rowsAboutToBeRemoved(QModelIndex,int,int)));

        disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),

                   this, SLOT(_q_rowsRemoved(QModelIndex,int,int)));

        disconnect(d->model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),

                   this, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int)));

        disconnect(d->model, SIGNAL(columnsRemoved(QModelIndex,int,int)),

                   this, SLOT(_q_columnsRemoved(QModelIndex,int,int)));

        disconnect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)),

                   this, SLOT(_q_columnsInserted(QModelIndex,int,int)));

 

        disconnect(d->model, SIGNAL(modelReset()), this, SLOT(reset()));

        disconnect(d->model, SIGNAL(layoutChanged()), this, SLOT(_q_layoutChanged()));

    }

    d->model = (model  model : QAbstractItemModelPrivate::staticEmptyModel());

 

    // These asserts do basic sanity checking of the model

    Q_ASSERT_X(d->model->index(0,0) == d->model->index(0,0),

               "QAbstractItemView::setModel",

               "A model should return the exact same index "

               "(including its internal id/pointer) when asked for it twice in a row");

    Q_ASSERT_X(d->model->index(0,0)parent() == QModelIndex(),

               "QAbstractItemView::setModel",

               "The parent of a top level index should be invalid");

 

    if (d->model != QAbstractItemModelPrivate::staticEmptyModel()) {

        connect(d->model, SIGNAL(destroyed()),

                this, SLOT(_q_modelDestroyed()));

        connect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),

                this, SLOT(dataChanged(QModelIndex,QModelIndex)));

        connect(d->model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),

                this, SLOT(_q_headerDataChanged()));

        connect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),

                this, SLOT(rowsInserted(QModelIndex,int,int)));

        connect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),

                this, SLOT(rowsAboutToBeRemoved(QModelIndex,int,int)));

        connect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),

                this, SLOT(_q_rowsRemoved(QModelIndex,int,int)));

        connect(d->model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),

                this, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int)));

        connect(d->model, SIGNAL(columnsRemoved(QModelIndex,int,int)),

                this, SLOT(_q_columnsRemoved(QModelIndex,int,int)));

        connect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)),

                this, SLOT(_q_columnsInserted(QModelIndex,int,int)));

 

        connect(d->model, SIGNAL(modelReset()), this, SLOT(reset()));

        connect(d->model, SIGNAL(layoutChanged()), this, SLOT(_q_layoutChanged()));

    }

<span style="color: #FF0000;">

    QItemSelectionModel selection_model = new QItemSelectionModel(d->model, this);

</span>

//这个TMD 怎么控制啊,大爷的,每次set 都来一个,我还没看到那边进行处理的。

//但可以肯定的是不断的setModel 我感觉100% 内存泄露

    connect(d->model, SIGNAL(destroyed()), selection_model, SLOT(deleteLater()));

    setSelectionModel(selection_model);

 

    reset(); // kill editors, set new root and do layout

}

//获取DGV中选中单元格中的值

例:

int id=convertToInt32(dgv1selectedRowd[0]cells["id"]values);

//选中的第一行的单元格dataPropertyName属性为Id的单元格中的值,

把获得的值赋给旁边的textboxtext

你可以试试看

ListView你都与给它设置了一个Adapter了,那么直接向Adapter要某个子view就行了。

比如BaseAdapter的:listAdaptergetItemView(int position);

当然你可能要给Adapter实现这个getItemView的方法,不然它默认返回null的。

以上就是关于求助QlistView-CSDN论坛全部的内容,包括:求助QlistView-CSDN论坛、C# DataGridView 怎么判断选 中的项、android中如何获取listview中某一项(非选中)中的子view等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9550687.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-29
下一篇 2023-04-29

发表评论

登录后才能评论

评论列表(0条)

保存