简体   繁体   English

将在Designer中创建的QWidget添加到QToolbar

[英]Add QWidget created in designer to a QToolbar

I have added a new designer form class to my project that is a widget. 我向我的项目添加了一个新的设计器表单类,它是一个小部件。 Using designer i have added some buttons and labels etc to the widget (which i want to use as my toolbar). 使用设计器,我向小部件添加了一些按钮和标签等(我想将其用作工具栏)。

The .cpp and .h files for the widget are untouched and basically just as they are when a new widget is created in qt. 小部件的.cpp和.h文件保持不变,基本上与在qt中创建新小部件时一样。

i have a different form that i have added a QToolbar to and now i want to add my widegt to that tool bar 我有一个不同的表单,我向其中添加了QToolbar,现在我想将我的widegt添加到该工具栏中

i added this code to my constructor of the form i want the toolbar on, m_horizontalToolBar was declared in the header like this std::shared_ptr<HorizontalToolbar> m_horizontalToolbar; 我将此代码添加到我希望在其上使用工具栏的表单的构造函数中,在标头中声明了m_horizo​​ntalToolBar,例如std::shared_ptr<HorizontalToolbar> m_horizontalToolbar;

QToolBar *tool = new QToolBar;
tool->addWidget(m_horizontalMapToolbar.get());
this->addToolBar(tool);

this compiles and runs but nothing displays in the toolbar 它将编译并运行,但工具栏中无任何显示

I have had a look at this question 我看了这个问题

The person seems to have got it working but it doesnt really say how at all 这个人似乎已经开始工作了,但并没有真正说出怎么做

seeing as how tool bar has an "addWidget" function i assume this is possible, any light on this would be helpful 鉴于工具栏如何具有“ addWidget”功能,我认为这是可能的,对此的任何浅谈都将有所帮助

您需要创建HorizontalToolbar类的实例。

m_horizontalMapToolbar = std::make_shared<HorizontalToolbar>();

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

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