手工编码 GUI 与 Qt Designer GUI

发布于 2024-07-10 21:09:27 字数 1449 浏览 14 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

追风人 2024-07-17 21:09:28

构建用户界面的不同部分
使用 QtDesigner 在不同的 .ui 文件中,
然后在代码中将它们组合在一起(并添加复杂性)。

有些事情在 Qt Designer 中无法完成,只能在代码中完成,
所以 Qt Designer 只是工具链的一个(重要)部分。

Build different parts of your UI
in different .ui files using QtDesigner,
then bring them together (and add complications) in code.

There are things you can't do in Qt Designer, you can only do in code,
so Qt Designer is just one (great) part of the tool chain.

徒留西风 2024-07-17 21:09:27

我们对 Designer 的体验始于 Qt3。

Qt3

此时,Designer 主要用于生成代码,然后将其编译到应用程序中。 我们开始为此目的使用,但对于所有生成的代码,一旦编辑它,您就无法再返回并重新生成它而不丢失您的编辑。 我们最终只使用生成的代码并手动完成此后的所有操作。

Qt4

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

我的评估是,它远不如 Mac OS X 上的 Interface Builder 那么有用,但此时,我可以看到直接在程序中使用 Designer 文件。

自 Qt3 以来,我们一直没有回到 Designer,但仍然使用它来进行原型设计和调试布局。

对于您的问题:

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

  2. 您可能会做一些更有限的事情,例如具有有限设计器功能的 xPad。

  3. 我不认为您可以仅使用 Designer 编写类似 OpenOffice 的内容,但也许这不是重点。

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

Our experience with Designer started in Qt3.

Qt3

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

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.

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

For your problems:

  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.

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

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

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.

难忘№最初的完美 2024-07-17 21:09:27

根据我使用 Qt Designer 和其他工具包/UI 工具的经验:

  • UI 工具可以加快工作速度。
  • UI 工具使以后调整布局变得更加容易。
  • UI 工具使非程序员可以更轻松/可能地进行 UI 设计。

通常可以通过将设计分解为多个 UI 文件来在 UI 工具中处理复杂性。 在每个文件中包含组件的小型逻辑组,并将每个组视为用于构建完整 UI 的单个小部件。 Qt Designer 的升级小部件概念可以帮助解决此问题。

我还没有发现项目的规模有什么不同。 您的体验可能会有所不同。

使用 UI 工具创建的文件(我想如果您确实愿意的话,您可以手动编写它们)通常可以在运行时动态加载(Qt 和 GTK+ 都提供此功能)。 这意味着您可以进行布局更改并测试它们,而无需重新编译。

最终,我认为原始代码和 UI 工具都是有效的。 这可能在很大程度上取决于环境、工具包/UI 工具,当然还有个人喜好。 我喜欢 UI 工具,因为它们可以让我快速启动和运行,并允许以后轻松更改。

In my experience with Qt Designer and other toolkits/UI-tools:

  • UI tools speed up the work.
  • UI tools make it easier to tweak the layout later.
  • UI tools make it easier/possible for non-programmers to work on the UI design.

Complexity can often be dealt with in a UI tool by breaking the design into multiple UI files. Include small logical groups of components in each file and treat each group as a single widget that is used to build the complete UI. Qt Designer's concept of promoted widgets can help with this.

I haven't found that the scale of the project makes any difference. Your experience may vary.

The files created with UI tools (I guess you could write them by hand if you really wanted to) can often be dynamically loaded at run-time (Qt and GTK+ both provide this feature). This means that you can make layout changes and test them without recompiling.

Ultimately, I think both raw code and UI tools can be effective. It probably depends a lot on the environment, the toolkit/UI-tool, and of course personal preference. I like UI tools because they get me up and running fast and allow easy changes later.

梦回旧景 2024-07-17 21:09:27

我工作的组织几年前已将其 GUI 应用程序移植到 Qt。
我认为有几个方面值得一提:

  • 使用 Qt Designer 工作,至少在当时,并不是一个现实的选择:有太多的功能无法使用 Qt Designer 完成;
  • 必须保留的约定和结构阻碍了 Qt Designer 的使用;
  • 一旦您在没有 Designer 的情况下开始使用,可能很难再回到它;
  • 但最重要的方面是,程序员非常习惯使用 vi 或 emacs 进行编程,而不是使用 GUI IDE。

我自己的经历,可以追溯到大约。 4年来,使用Qt3.3,对话框中的动态行为在Designer中无法实现。

The organisation I work for has ported its GUI application to Qt several years ago.
I think there are several aspects that are worth mentioning:

  • Working with Qt Designer, at least at that point, was not a realistic option: there were too many features that couldn't be done with Qt Designer;
  • Conventions and structure that had to be preserved prevented the use of Qt Designer;
  • Once you've started without Designer, it is probably difficult to return to it;
  • the most important aspect, though, was that the programmers were very much used to programming using vi or emacs, rather than using a GUI IDE.

My own experience, which goes back approx. 4 years, using Qt3.3, is that dynamic behavior in dialogs was not possible to realise in Designer.

妄断弥空 2024-07-17 21:09:27

只是说,我在 Qt 中编写和维护了复杂的 GUI,而没有使用 Qt Designer——不是因为我不喜欢 Qt Designer,而是因为我从来没有抽出时间以这种方式工作。

这在一定程度上是风格和你来自哪里的问题:当我开始使用 Qt 时,我对 Dreamweaver 和 Frontpage 以及其他可视化 HTML 工具有过可怕的经历,并且更喜欢使用 HomeSite 编写代码并诉诸 Photoshop 进行棘手的布局问题。

可视化代码 IDE 存在一个危险,您试图将其保留在可视化工具中,但最终也必须以不太容易理解的方式调整代码。

例如,学习 iPhone 开发时,我发现点击“神奇”的视觉内容(“从连接检查器中的空圆圈拖动到 Interface Builder 窗口中的对象......”)会更简单(对于我)用简单的旧代码来理解。

祝 Qt 好运——无论你如何使用它,它都是一个很棒的工具包,而且 Qt Creator 看起来是一个很棒的 IDE。

Just to say I've written and maintained complex GUIs in Qt without using Qt Designer -- not because I don't like Qt Designer, but because I never got around to working that way.

It's partly a matter of style and where you're coming from: when I started on Qt, I'd had horrible experiences of Dreamweaver and Frontpage and other visual HTML tools,and far preferred writing code with HomeSite and resorting to Photoshop for tricky layout problems.

There's a danger with visual code IDEs that you try to keep within the visual tools, but end up having to tweak code as well -- in ways that aren't well understood.

Learning iPhone development, for example, I've found it frustrating to hit 'magic' visual stuff ('drag from the empty circle in the Connections inspector to the object in the Interface Builder window...') that would be simpler (for me) to understand in plain old code.

Good luck with Qt -- it's a great toolkit, however you use it, and Qt Creator looks like being a great IDE.

十雾 2024-07-17 21:09:27

我想补充一点,例如,使用图形设计器的原因之一是 Win32 中缺乏布局管理器。 只能进行绝对定位,而手动进行则很糟糕。

自从我从 Delphi 转向 Java 来开发 GUI 应用程序(早在 2002 年),我就再也没有使用过设计器。 我更喜欢布局管理器。 是的,您可以获得样板代码,但是在 UI 设计器上移动对象可能需要与更改样板一样多的时间。 另外,我会被一个缓慢的 IDE 困住; 这是针对 Java/C# 的情况,好的,而对于 Qt(尤其是 Qt4)则不适用。 对于 Qt3,我想知道为什么要编辑生成的代码 - 难道不能在其他文件中添加代码吗? 出于什么原因?

关于讨论的案例:
1) 手工编码的 GUI 可能写起来更快,至少如果你了解你的库的话。 如果您是新手并且不了解它们,那么向设计师学习可能会节省时间并减少学习量,因为您不需要学习所使用的 API。 但“少学”是关键因素,所以在这两种情况下我都会说手工编码 GUI。

2)菜单栏编写代码非常烦人。 另外,请考虑加速器等细节。 不过,这取决于您的习惯。 一段时间后,键入样板文件可能比点击设计器来修复所有这些属性更快,但前提是你真的可以像打字机一样键入(就像那些管理员,键入 Unix 命令比键入 Unix 命令更快)使用任何 GUI)。

3)我会将案例#2 的答案扩展到这个案例。 请注意,对于 Win32 平台,使用生成 Win32 资源的设计器可能可能加载速度更快(不知道这一点)。

不过,我想提一下使用 Qt Designer 的一个潜在问题。 真实案例:加载一个包含大量选项的复杂 Java 对话框(程序员文本编辑器的首选项对话框)需要几秒钟(比如 10 秒)。 正确的解决方法是仅当程序员想要查看每个选项卡时(我后来意识到),通过向每个首选项集添加一个单独的方法来构建其 GUI,才加载每个选项卡。

如果您与设计师一起设计所有选项卡和选项卡切换器,您可以轻松做到吗? 我想可能有一个类似的例子,其中手工编码的 GUI 为您提供了更大的灵活性,并且在如此大的应用程序中,您可能需要它,即使只是为了优化目的。

I'd add that one of the reasons for using graphical designer was the lack of layout managers in Win32, for instance. Only absolute positioning was possible, and doing that by hand would have just sucked.

Since I switched from Delphi to Java for GUI apps (back in 2002), I've never used designers any more. I like layout managers much more. And yeah, you get boilerplate code, but moving objects on a UI designer may take as much time as changing the boilerplate. Plus, I would be stuck with a slow IDE; that's for the Java/C# case, OK, while for Qt (especially Qt4) it doesn't apply. For Qt3, I wonder why one should edit the generated code - wasn't it possible to add code in other files? For which reason?

About the discussed cases:
1) Hand Coded GUI is likely faster to write, at least if you know your libraries. If you're a newbie and you don't know them, you may save time and learn less with a designer, since you don't need to learn the APIs you use. But "learn less" is the key factor, so in both cases I'd say Hand Coded GUI.

2) Menu bars are quite annoying to write code for. Also, think to details like accelerators and so on. Still, it depends on what you're used to. After some time, it may be faster to type that boilerplate than to point-and-click into designer to fix all those properties, but just if you can really type like into a typewriter (like those admins for which typing Unix commands is faster than using any GUI).

3) I'd extend the answer for case #2 to this one. Note that, for Win32 platforms, it may be possible that using designers which generate Win32 resources might be faster to load (no idea about that).

However, I'd like to mention a potential problem with using Qt Designer there. Real world case: it took some seconds (say 10) to load a complex Java dialog (the Preferences dialog box for a programmer's text editor) with a lot of options. The correct fix would have been to load each of the tabs only when the programmer wanted to see them (I realized that after), by adding a separate method to each preference set to build its GUI.

If you design all the tabs and the tab switcher together with a designer, can you do that as easily? I guess there might be a similar example where a hand coded GUI gives you more flexibility, and in such a big app, you're likely to need that, even if just for optimization purposes.

伴随着你 2024-07-17 21:09:27

使用设计器创建 GUI 的主要好处之一是其他程序员可以轻松更改或维护表单和小部件,而无需深入研究复杂的代码。

One of the main benefits of using designer to create GUIs is that other programmers can change or maintain forms and widgets easily without the need to delve in to a complex code.

破晓 2024-07-17 21:09:27

奇怪的是,您说编写代码比在图形环境中操作对象更简单。 这是理所当然的。
设计器的作用是让您的生活更轻松,从长远来看,它使您的代码更易于维护。 在设计器中查看 UI 的外观,然后阅读代码并尝试想象它可能是什么样子,会更容易。
使用当前的 Qt,您几乎可以在设计器中完成所有操作,而您不能做的极少数事情,您可以在构造函数中使用很少的代码行来修复。
举个最简单的例子——添加信号槽连接。 使用设计器就像双击一样简单。 如果没有设计器,您需要查找信号的正确签名,编辑 .h 文件,然后在 .cpp 文件中编辑编写代码。 设计器使您能够超越这些细节并专注于真正重要的事情 - 您的应用程序的功能。

Its strange that you're saying the writing code is simpler than manipulating objects in a graphical environment. It's a no-brainer.
The designer is there to make your life easier and in the long term it makes your code more maintainable. It's easier looking in the designer to see what the your UI looks like then reading the code and trying to imagine what it might look like.
With current Qt you can do almost everything from within the designer and the very few things you can't do, you can fix with very few lines of code in the constructor.
Take for instance the simplest example - adding a signal-slot connection. Using the designer it's as simple as a double click. Without the designer you need to go lookup the correct signature of the signal, edit the .h file and then edit write your code in the .cpp file. The designer allows you to be above these details and focus on what really matters - the functionality of your application.

数理化全能战士 2024-07-17 21:09:27

我喜欢首先请设计师来开发 GUI 小部件。 正如其他帖子中提到的,它更快。 您还可以获得即时反馈,看看它是否“看起来正确”并且不会让用户感到困惑。 设计师是我选择 Qt 而不是其他工具包的主要原因。
我主要使用设计器来制作一次性对话框。

话虽如此,我还是手工制作主窗口和任何复杂的小部件。
我认为这就是奇趣科技的初衷。 QFormLayout 是他们提供的一个类,用于轻松地以编程方式创建输入对话框。

顺便说一下,Qt 4 中的设计器并不是像 Qt 3 中那样的 IDE。它只是一个用于编辑 .ui 文件的编辑器。 我喜欢这样。 新的跨平台 IDE 将被称为 Qt Creator。

I like to first turn to the designer to develop GUI widgets. As mentioned in the other posts, its faster. You also get immediate feedback to see if it "looks right" and isn't confusing to the user. The designer is a major reason I choose Qt over other toolkits.
I mostly use the designer to make the one-off dialogs.

Having said that, I do the main window and any complex widgets by hand.
I think this is the way Trolltech intended. QFormLayout is a class they provide to easily programatically create an input dialog.

By the way, the designer in Qt 4 is not an IDE like the one they had in Qt 3. It's just an editor for editing .ui files. I like it that way. The new cross platform IDE is going to be called Qt Creator.

ら栖息 2024-07-17 21:09:27

这是一篇旧文章,但我建议您看看 Clementine - 一个音乐播放器(我认为)源自 Amarok。 他们使用 Qt4,从我可以看到项目的 src 文件夹中有一个 ui 文件夹。 正如人们所期望的,在 ui 文件夹中,它们包含各种 .ui 文件。 如果您编译并启动 Clementine,您会发现 GUI 相当复杂且非常漂亮。

It's an old post but I would advise you to look at Clementine - a music player which (I think) derives from Amarok. They use Qt4 and from what I can see there is a ui folder in the src folder of the project. In the ui folder as one might expect they have all sorts of .ui files. If you compile and start Clementine you will see that the GUI is fairly complex and quite nice.

伴我心暖 2024-07-17 21:09:27

对我来说,这取决于小部件/GUI 中封装了多少逻辑。 如果只是简单的表单,我更喜欢使用 QtDesigner。

如果它包含复杂的检查或交互,我倾向于对其进行编程。

For me, it depends how much logic is encapsulated in the widget/GUI. If it's just about simple forms, I prefer to use QtDesigner.

If it contains complex checks or interaction, I tend to program it.

丢了幸福的猪 2024-07-17 21:09:27

如果有人需要创建 Gui,我们将使用 Qt Designer。
问题是为某些任务创建一些小部件(就像您在类设计中所做的那样),然后将它们组合在一起形成“父 GUI”。

这样,您的小部件就具有高度可重用性,并且可以以模块化方式用于 Guis。 您只需指定每个 Widget 发送哪些信号以及它们提供哪些插槽。

我们还创建了在构建过程中生成的 .ui 文件。 到目前为止,还不需要手动编辑这些文件。

We're using the Qt Designer if anyone needs to create a Gui.
The thing is to create just little Widgets for certain tasks (like you would do in a class-design) and then get them together into a "parent-gui".

This way your widgets are highly reusable and could be used for Guis in a modular way. You just have to specify which signals each Widget is sending and which slots they provide.

We additionally are creating .ui-Files which than could be generated during build-process. Until now there was no need to edit those files by hand.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文