Qt 设计器与手工编码 [英] Qt Designer vs Handcoding

查看:20
本文介绍了Qt 设计器与手工编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我使用一些图形工具包开始一个项目时,第一个冲突都会发生在如何处理视觉设计和小部件布局的决定上:图形工具还是手工编码?

Every time I start a project with some graphical toolkit, one of the first conflicts happen with the decision of how to deal with the visual design and the widget layout: A graphical tool or handcoding?

这是一个相当棘手/主观的问题,因为大多数人会根据个人喜好做出决定.它还很大程度上取决于图形工具的质量.在这种情况下,我想只关注最新版本的 QT 库.我不打算讨论哪种方法更好.我相信最好的答案是:取决于项目.

This is a quite tricky/subjective question because most people will decide based on personal preference. It also depends greatly on the quality of the graphical tool. In this case I would like to focus just on the latest version of the QT library. I do not intend to discuss which method is better. I am convinced that the best answer is: depends on the project.

我想要的是参考一篇好的无偏见文章,基于几个项目的经验.文章应该只描述两种选择的权衡

What I want is a reference to a good non biased article, based on experience after several projects. The article should just describe the tradeoffs of both choices

推荐答案

我开始做所有的事情都是手工编码的,最近已经切换到使用 Qt Designer 来处理大多数表单.以下是每个职位的一些好处:

I started with doing everything hand-coded, and of late have been switching to using Qt Designer for most forms. Here are some benefits for each position:

使用 Qt 设计器

  • 对我来说最节省时间的是管理复杂的布局;它节省了很多繁琐的编码.只需(非常粗略地)排列您的小部件,选择它们,右键单击,然后将它们放在正确的布局类型中.特别是当布局变得嵌套时,这所以要容易得多.
  • 它倾向于使您的实现文件更简洁,而不是用所有样板布局代码填充它们.我是 A 型,所以我喜欢这样.
  • 如果您正在翻译您的应用程序,可以将 .ui 文件发送给您的翻译人员,以便他们可以在您的 GUI 上查看他们正在翻译的文本所在的位置.(假设他们使用的是 Qt Linguist.)
  • The biggest time saver for me is managing complex layouts; it saves a lot of tedious coding. Simply (very roughly) arrange your widgets, select them, right-click, and put them in the correct type of layout. Especially as layouts become nested, this is so much easier.
  • It tends to keep your implementation files cleaner instead of filling them with all the boilerplate layout code. I'm type-A, so I like that.
  • If you are translating your application, it is possible to send your translators the .ui files so they can see on your GUI where the text they are translating will be. (Assuming they are using Qt Linguist.)

手工编码

  • 控制.如果您的布局需要以非常特定的顺序实例化/初始化控件,或者根据其他条件(数据库查找等)动态创建控件,这是最简单的方法.
  • 如果您有自定义小部件,您可以使用设计器,添加最接近您的类派生的内置 QWidget,然后升级"它.但您不会看到小部件的预览,除非您将其作为单独项目中的设计器插件,这对于大多数用例来说工作量太大.
  • 如果您的自定义小部件在其构造函数中采用可选 QWidget 父级之外的参数,则 Designer 无法处理.您别无选择,只能手动添加该控件.

杂项

  • 使用自动连接 SLOTS 和 SIGNALS 功能(基于命名约定,例如on_my_button_clicked".)我发现我几乎总是必须在确定时间,而不是 Qt 为我做的任何时候.
  • 对于 QWizard 表单,我发现我需要为每个页面使用不同的 UI 文件.您可以一次性完成所有操作,但以任何一种自定义方式在页面之间进行通信都会变得非常尴尬.
  • I don't use the auto-connect SLOTS and SIGNALS feature (based on naming convention such as "on_my_button_clicked".) I have found that I almost invariably have to set up this connection at a determinate time, not whenever Qt does it for me.
  • For QWizard forms, I have found that I need to use a different UI file for each page. You can do it all in one, but it becomes very awkward to communicate between pages in any kind of custom way.

总之,我从 Qt Designer 开始,让它尽可能地带我走,然后从那里手动编码.这是 Qt Designer 生成的一件好事——它只是成为您的类的成员的另一个类,您可以根据需要访问和操作它.

In summary, I start with Qt Designer and let it take me as far as it can, then hand-code it from there. That's one nice thing about what Qt Designer generates--it is just another class that becomes a member of your class, and you can access it and manipulate it as you need.

这篇关于Qt 设计器与手工编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆