PyQt 自动重复表格
我目前正在尝试将旧版 VBA/Microsoft Access 应用程序迁移到 Python 和 PyQt。 我在迁移任何逻辑时都没有遇到任何问题,而且大多数表单也很容易实现。 但是,我在应用程序最重要的部分(主要数据输入表单)上遇到了问题。
该表单基本上是与数据库中的字段相对应的一行文本框。 用户只需将数据输入到字段中,然后按制表符切换到下一个字段并重复。 当他到达记录/行的末尾时,他再次按 Tab 键,表单会自动创建一个新的空白行,供他再次开始输入数据。 (实际上,它在当前新记录下方显示一个“空白”行,用户实际上也可以单击该行来开始新记录。)它还允许用户上下滚动以查看所有当前子集他正在处理的记录。
有没有办法在 PyQt 中复制这个功能? 我还没有找到一种方法让 Qt 轻松地做到这一点。 Access 会自动处理它; 不需要表单之外的代码。 在 PyQt 中是那么容易(甚至接近),还是需要从头开始编程?
I'm currently attempting to migrate a legacy VBA/Microsoft Access application to Python and PyQt. I've had no problems migrating any of the logic, and most of the forms have been a snap, as well. However, I've hit a problem on the most important part of the application--the main data-entry form.
The form is basically a row of text boxes corresponding to fields in the database. The user simply enters data in to a fields, tabs to the next and repeats. When he comes to the end of the record/row, he tabs again, and the form automatically creates a new blank row for him to start entering data in again. (In actuality, it displays a "blank" row below the current new record, which the user can actually click in to to start a new records as well.) It also allows the user to scroll up and down to see all the current subset of records he's working on.
Is there a way to replicate this functionality in PyQt? I haven't managed to find a way to get Qt to do this easily. Access takes care of it automatically; no code outside the form is required. Is it that easy in PyQt (or even close), or is this something that's going to need to be programmed from scratch?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该查看 QSqlTableModel 和 QTableView 对象。 QSqlTableModel 提供了可以在 Qt 视图类内部使用的关系表的抽象。 以 QTableView 为例。 您描述的功能只需使用这两个类即可轻松实现。
QSqlTableModel 还支持对数据库字段进行编辑。
我猜您必须手动实现的唯一功能是表末尾的“TAB”,如果您想保留它,则可以创建一个新行。
我对 Access 不太了解,但是使用 ODBC-SQL 驱动程序,您应该能够使用实际的 Access 数据库进行开发或测试,有一些较旧的信息 此处,您可能需要考虑迁移到 Sqlite、Mysql 或其他实际的SQL 数据库。
You should look into QSqlTableModel, and the QTableView Objects. QSqlTableModel offers an abstraction of a relational table that can be used inside on of the Qt view classes. A QTableView for example. The functionality you describe can be implemented with moderate effort just by using these two classes.
The QSqlTableModel also supports editing on database fields.
My guess the only functionality that you will have to manually implement is the "TAB" at the end of the table to create a new row if you want to keep that.
I don't know much about Access, but using the ODBC-SQL driver you should be able use the actual access database for your development or testing there is some older information here, you might want to consider moving to Sqlite, Mysql or another actual SQL database.