Qt 数据库内容视图/操作为列表视图
我有一个数据库,应该在小部件中查看哪些表。看起来很简单,但我无法决定要使用什么。
表的每一行都应被视为一个列表视图项,例如,想象一下具有以下字段的表:id、标题、内容、日期、数字。
我需要将其视为列表视图(不是硬编码,它也可能是另一件事,如果可能或更好),并且列表视图项的标签应该是标题字段。但是,当用户单击或双击该项目时,它应该在单独的小部件中打开当前行的所有内容。所有这些都可以由我轻松实现,但我不明白该使用什么:QListView及其模型,还是QListWidget?或者也许是 QSqlTableModel?最后一个对我来说不熟悉,我可以从文档中阅读,但是如果您听说过或遇到过某种事物/应用程序,请为所描述的问题提供更好的解决方案。
希望我能正确解释我的问题, 提前致谢。
I have a database, which tables should viewed in a widget. Seems simple, but I can't decide what to du or use.
Each row of the table should be viewed as one list view item, for instance, imagine table with this fields: id, title, content, date, number.
I need to view it as a list view (not hard-coded, it may also be another thing, if it is possible or better), and the label of the list view item should be the title field. But when the user clicks or double clicks on that item it should open all the contents of the current row in a separate widget. The all of these can be implemented easily by me, but I can't understand what to use: QListView with its model, or QListWidget? Or maybe QSqlTableModel? The last one is unfamiliar to me, I can read about from documentation, but if you have heard or met some kind things/applications, please provide a better solution for described problem.
Hope I could explain my problem correctly,
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否阅读过Qt 中的模型/视图编程?基本上你应该使用一些模型(QSqlTableModel、QSqlQueryModel、QSqlRelationalTableModel 或创建你自己的),然后将其附加到 QListView 或 QListWidget。
Have you read about model/view programming in Qt? Basically you should use some model (QSqlTableModel, QSqlQueryModel, QSqlRelationalTableModel or create your own) an then attach it to QListView or QListWidget.