如何用QSqlTableModel中的列替换行? [英] How to replace rows with columns in QSqlTableModel?
问题描述
我找到了很多关于如何在 SQL 中将行转换为列的答案.但是我需要在 QSqlTableModel 中将行转换为列.据我所知,这应该不是一项非常艰巨的任务,但我找不到如何实现它的任何想法.也许可以重新实现 data()、setData() 和其他一些方法,但我害怕错过一些东西...
I found a lot of answers how to transform rows into columns in SQL. But I need to transforms rows into columns in QSqlTableModel. As I understand it should not be a very difficult task but I can't find any idea of how to realize it. Perhaps data(), setData() and some other methods could be reimplemented, but I am afraid to miss something...
或者,也许应该重新实现 QTableView 的一些方法.
Or, maybe, some methods of QTableView should be reimplemented.
推荐答案
据我所知 QIdentityProxyModel 可以用来解决这个问题.不幸的是,QIdentityProxyModel 从 4.8 版开始可用.
As I understand QIdentityProxyModel could be used to solve this problem. Unfortunately, QIdentityProxyModel is available since version 4.8.
所以我继承了 QAbstractProxyModel 并实现了 mapToSource() 和 mapFromSource()、rowCount()、columnCount() 和更多的方法来切换行与列.
So I inherited QAbstractProxyModel and implemented mapToSource() and mapFromSource(), rowCount(), columnCount() and few more methods to switch rows with columns.
这篇关于如何用QSqlTableModel中的列替换行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!