手工编码 GUI 与 Qt 设计器 GUI

Hand Coded GUI Versus Qt Designer GUI(手工编码 GUI 与 Qt 设计器 GUI)

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

问题描述

我利用这些假期学习编写 Qt 应用程序.几个小时前,我正在阅读有关 Qt Designer 的文章,这让我想知道:在 Qt 中编写真实世界应用程序的人使用什么来设计他们的 GUI?事实上,人们一般是如何设计 GUI 的?

I'm spending these holidays learning to write Qt applications. I was reading about Qt Designer just a few hours ago, which made me wonder : what do people writing real world applications in Qt use to design their GUIs? In fact, how do people design GUIs in general?

一方面,我发现手工编写代码在概念上比使用 Qt Designer 更简单,但对于复杂的 GUI,Designer 可能更有意义.使用 Designer 可能可以实现大型 GUI,但随着时间的推移,随着复杂性的增加,它们可能变得非常难以管理(这只是我的意见).我还下载了 AmaroK 源代码来看看那些人在做什么,并发现了许多对 addWidget() 和朋友的调用,但没有一个由 Designer 创建的 XML 文件(除此之外:AmaroK 必须是我最喜欢的应用程序)任何平台).

I, for one, found that writing the code by hand was conceptually simpler than using Qt Designer, although for complex GUIs Designer might make sense. Large GUIs might be possible using Designer, but with time they might become very difficult to manage as complexity increases (this is just my opinion). I also downloaded the AmaroK source code to take a peek at what those guys were doing, and found many calls to addWidget() and friends, but none of those XML files created by Designer (aside: AmaroK has to be my favorite application ever on any platform).

那么,什么是创建 GUI 的正确"方式?设计师还是代码?在此讨论中,让我们考虑以下类型的 GUI:

What, then, is the "right" way to create a GUI? Designer or code? Let us, for this discussion, consider the following types of GUIs :

  1. 简单的对话框,只需要输入、显示一些结果并退出.让我们假设一个应用程序使用 YouTube URL 并将视频下载到用户的硬盘上.新手可能会开始使用的应用程序类型.
  2. 中级 GUI,例如带有一些工具栏/菜单项的便签编辑器.让我们以 xPad 为例(http://getxpad.com/).我会说大多数应用程序都属于实用程序"类别.
  3. 非常复杂的 GUI,例如 AmaroK 或 OpenOffice.当您看到它们时,您就知道它们,因为它们使您的眼睛流血.
  1. Simple dialogs that just need to take input, show some result and exit. Let's assume an application that takes a YouTube URL and downloads the video to the user's hard disk. The sort of applications a newbie is likely to start out with.
  2. Intermediate level GUIs like, say, a sticky notes editor with a few toolbar/menu items. Let's take xPad for example (http://getxpad.com/). I'd say most applications falling in the category of "utilities".
  3. Very complex GUIs, like AmaroK or OpenOffice. You know 'em when you see 'em because they make your eyes bleed.

推荐答案

我们使用 Designer 的经验始于 Qt3.

Our experience with Designer started in Qt3.

Qt3

那时,Designer 主要用于生成代码,然后您可以将这些代码编译到您的应用程序中.我们开始为此目的而使用所有生成的代码,一旦您编辑它,您就无法再返回并重新生成它而不会丢失您的编辑.我们最终只使用生成的代码并在此之后手工完成所有事情.

At that point, Designer was useful mainly to generate code that you would then compile into your application. We started using for that purpose but with all generated code, once you edit it, you can no longer go back and regenerate it without losing your edits. We ended up just taking the generated code and doing everything by hand henceforth.

Qt4

Qt4 在 Designer 上有显着改进.它不再只生成代码,但您可以动态加载您的设计器文件(在 xml 中)和 将它们动态连接到程序中正在运行的对象 -- 无需生成代码,但是,您必须在 Designer 中命名这些项目并坚持使用这些名称以免破坏您的代码.

Qt4 has improved on Designer significantly. No longer does it only generate code, but you can dynamically load in your Designer files (in xml) and dynamically connect them to the running objects in your program -- no generated code however, you do have to name the items in Designer and stick with the names to not break your code.

我的评估是,它远不如 Mac OS X 上的 Interface Builder 有用,但在这一点上,我可以看到直接在程序中使用 Designer 文件.

My assessment is that it's nowhere near as useful as Interface Builder on Mac OS X, but at this point, I could see using the Designer files directly in a program.

自从 Qt3 以来,我们就没有再使用 Designer,但仍然使用它来进行原型设计和调试布局.

We haven't moved back to Designer since Qt3, but still use it to prototype, and debug layouts.

对于您的问题:

  1. 您可能可以使用 Qt 提供的标准对话框.QInputDialog 或者如果您继承 QDialog,请确保使用 QButtonDialogBox以确保您的按钮具有正确的平台布局.

  1. You could probably get away with using the standard dialogs that Qt offers. QInputDialog or if you subclass QDialog, make sure to use QButtonDialogBox to make sure your buttons have the proper platform-layout.

您可能可以使用有限的 Designer 功能来做一些更有限的事情,例如 xPad.

You could probably do something more limited like xPad with limited Designer functionality.

我不认为你可以单独使用 Designer 编写类似 OpenOffice 的东西,但也许这不是重点.

I wouldn't think you could write something like OpenOffice solely with Designer but maybe that's not the point.

我会将 Designer 用作另一种工具,就像您的文本编辑器一样.找到限制后,请尝试使用不同的工具来解决新问题.我完全同意 Steve S 的观点,即 Designer 的一个优点是其他不是程序员的人也可以进行布局.

I'd use Designer as another tool, just like your text editor. Once you find the limitations, try a different tool for that new problem. I totally agree with Steve S that one advantage of Designer is that someone else who's not a programmer can do the layout.

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

本文标题为:手工编码 GUI 与 Qt 设计器 GUI

基础教程推荐