Qt设计师vs手写 [英] Qt Designer vs Handcoding

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

问题描述

每次我使用一些图形工具包启动一个项目时,最初的冲突之一是如何处理视觉设计和小部件布局的决定:图形工具或手写编码?

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 Designer


  • 对我来说最大的节省时间是管理复杂的布局;它节省了很多冗长的编码。只需(非常粗略地)安排您的小部件,选择它们,右键单击,并将它们放置在正确的布局类型。

  • 它倾向于保持你的实现文件更清洁,而不是填充所有的样板布局代码。我是A型,所以我喜欢。

  • 如果您正在翻译您的应用程序,可以发送您的翻译.ui文件,以便他们可以看到在你的GUI上,他们正在翻译的文本将是。 (假设他们正在使用Qt语言学家。)

  • 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.)

手写代码


  • 控制。如果您有一个布局,您需要以非常特定的顺序实例化/初始化控件,或者基于其他条件(数据库查找等)动态创建控件,这是最简单的方法。

  • 如果你有自定义的小部件,你可以使用Designer,添加最近的内置QWidget从你的类派生,然后升级。但是你不会看到你的小部件的预览,除非你在一个单独的项目中设计一个设计器插件,这在大多数情况下是太多的工作。

  • 如果你有自定义小部件在其构造函数中接受可选QWidget父元素之外的参数,Designer无法处理它。您只能手动添加该控制。

其他


  • 我不要使用自动连接SLOTS和SIGNALS功能(基于命名约定,如on_my_button_clicked)。我发现

  • 对于 QWizard 表单,我必须在确定的时间建立此连接,而不是每当Qt为我建立连接。我发现我需要为每个页面使用不同的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设计师开始,让它尽可能的,然后手动代码从那里。这是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设计师vs手写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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