简体   繁体   English

Qt Designer的自定义动作插件

[英]Custom action plugin for Qt Designer

I plan to use a spacer in my toolbar (below) between the 'Pause' and 'Settings' buttons to make the 'Settings' button right-aligned within the QToolBar . 我计划在工具栏(在下面)中的“暂停”和“设置”按钮之间使用一个空格,以使“设置”按钮在QToolBar右对齐。 The separator below isn't cutting it. 下面的分隔符没有切割它。

工具栏需要垫片

The following method apparently works, although I haven't actually tried it yet: 以下方法显然有效,尽管我实际上尚未尝试过:

QWidget* spacer = new QWidget();
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// toolBar is a pointer to an existing toolbar
toolBar->addWidget(spacer);
toolBar->addAction("Right-aligned button");

(thanks to http://www.ffuts.org/blog/right-aligning-a-button-in-a-qtoolbar/ ) (感谢http://www.ffuts.org/blog/right-aligning-a-button-in-a-qtoolbar/

Qt Designer doesn't seem to allow adding widgets to a QToolBar , although QToolBar does have an addWidget() method, as used above. Qt设计似乎不允许添加小部件一个QToolBar ,虽然QToolBar确实有一个addWidget()方法,如以上使用。 So if I want to be able to add the spacer to my toolbar using Qt Designer (with a plugin, not promotion), should I subclass QAction , QWidget , or QWidgetAction ? 因此,如果我希望能够使用Qt Designer(使用插件而不是促销产品)将间隔器添加到工具栏,是否应该将QActionQWidgetQWidgetAction子类QWidgetAction Is there even a way to write custom action plugins for Qt Designer? 甚至还可以为Qt Designer编写自定义操作插件吗?

You cannot subclass QAction and expect to use it gracefully in Qt Creator/Designer. 您不能继承QAction并期望在Qt Creator / Designer中正常使用它。 It uses the tags in the ui and to add them to menus and toolbars. 它使用ui中的标签并将其添加到菜单和工具栏。 You can't specify a class="customclass" element along with a entry like other widgets. 您不能将class =“ customclass”元素与其他小部件之类的条目一起指定。 Because actions are treated differently, you cant even subclass them so that's out. 因为对动作的区别对待,所以您甚至不能将其子类化,这样就可以了。

As for QWidgetAction/QWidget, you are in the same boat as QActionGroup, if you know what I mean. 对于QWidgetAction / QWidget,如果您知道我的意思,那么您与QActionGroup在同一条船上。 (I personally think this is a big overlook in the design of the form designer!) So previewing that in the designer is also out. (我个人认为这在表单设计器的设计中是一个很大的疏漏!)因此在设计器中进行预览也是可以的。

The last thing you could do (invisible option 3) is QToolbar subclassing, but alas you can subclass it, but still, you wont be seeing anything in the desinger other than what a plain old QToolbar can do. 您可以做的最后一件事(不可见的选项3)是QToolbar的子类化,但是您可以对它进行子类化,但是,除了普通的旧QToolbar可以做的之外,您仍然不会在设计器中看到任何东西。 That doesnt mean that it is completely out which is the point I'm coming to: 这并不意味着完全解决了我要讲的重点:

The real answer would have to be invisible option 4, subclassing QToolbar as a designer plugin (which would require a lot of coding on your part if you dont already know of one that is out there, I dont know of any that actually have designer plug-ins) Form Designer plugins are more not than often, but you could find someone's subclassed toolbar, and make it into a plugin yourself saving you a step (qt creator even has a template for that), then use it in qt designer and your set. 真正的答案必须是不可见的选项4,将QToolbar子类化为设计器插件(如果您还不知道那里有一个插件,那我将需要大量编码,而我不知道实际上有设计器插件的任何插件) -ins)Form Designer插件不多见,但您可以找到某人的子类工具栏,然后自己将其制作成插件,从而节省了一步(qt创建者甚至具有该模板),然后在qt designer和您的组。

I know this question got asked 2 years ago but when I see an unanswered question, I think of those searchers that might read and get frustrated by a dead-end so if I can contribute I do... I hope I did at least help you or anyone else get on the right track, and good luck to you all! 我知道这个问题是在2年前提出的,但是当我看到一个未解决的问题时,我想到的是那些可能会阅读并陷入僵局的搜索者,所以如果我能做出贡献,我会做...我希望我至少能帮上忙您或任何其他人走上正轨,祝大家好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM