Qt Qtableview 没有收到标题项点击信号
我使用 Qtableview
和 QsqlTableModel
来填充表数据。我想根据列标题上的用户选择对列进行排序。
我尝试了 QTableView 排序信号? 中提到的方式来获取信号(从 QtableView
并连接信号 sectionclicked(int逻辑索引)
但当我单击列标题时,没有发出相同的信号,
请找到完成连接的代码:
。成员变量:
QHeaderView *m_horiz_header;
.cpp 文件
m_sqltablemodel->setTable(tabel_name);
m_sqltablemodel->setEditStrategy(QSqlTableModel::OnManualSubmit);
m_sqltablemodel->select();
m_horiz_header= m_table_view->horizontalHeader();
connect(m_horiz_header, SIGNAL(sectionClicked ( int logicalIndex ) ),
this, SLOT(on_sectionClicked ( int logicalIndex ) ));
用于排序的槽函数:
void class::on_sectionClicked ( int logicalIndex )
{
m_horiz_header->setSortIndicator(logicalIndex, Qt::AscendingOrder);
m_table_view->sortByColumn(logicalIndex);
}
单击列标题时不会调用此函数,
您能帮我解决一下吗?这,我哪里错了?
I am using Qtableview
with QsqlTableModel
for populating a table data. I want to sort the column based on user selection on column header.
I tried the way mentioned in QTableView sorting signal? for getting the signal (get the horizontal header from QtableView
and connect signal sectionclicked(int logical index)
. But the same signal is not getting emitted when i click on column header.
Please find the code where connection is done:
Member variable:
QHeaderView *m_horiz_header;
.cpp file
m_sqltablemodel->setTable(tabel_name);
m_sqltablemodel->setEditStrategy(QSqlTableModel::OnManualSubmit);
m_sqltablemodel->select();
m_horiz_header= m_table_view->horizontalHeader();
connect(m_horiz_header, SIGNAL(sectionClicked ( int logicalIndex ) ),
this, SLOT(on_sectionClicked ( int logicalIndex ) ));
Slot function for sorting:
void class::on_sectionClicked ( int logicalIndex )
{
m_horiz_header->setSortIndicator(logicalIndex, Qt::AscendingOrder);
m_table_view->sortByColumn(logicalIndex);
}
This function is not getting called, when column header is clicked.
Can you please help me how to do this, where I went wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道信号连接失败的原因了。
连接时不应提及参数名称。
通过像这样修改上面的代码,它起作用了。
I got the reason why the signal connection failed.
argument name should not be mentioned on connect.
by modifiying the above code like this, it worked.