QWidget中的浮动/嵌入QDockWidget(在QT Designer中设计的KXmlGuiWindow的CentralWidget)
我只是想进入 QT(和 KDE)程序,并在尝试将可浮动、可拖动的 QDockWidget
添加到 .ui 文件(基于 QWidget
code>) 嵌入到我的 KDE 4 程序中。
这全部来自 KDevelop 4 提供的基本模板,所以虽然我了解发生了什么,但我只是不知道更改它的最佳方法。
事情是这样的:main.cpp 生成一个新的 AEmpire
窗口,它开始整个展示:
AEmpire::AEmpire()
: KXmlGuiWindow(),
m_view(new AEmpireView(this)),
m_printer(0)
{
// tell the KXmlGuiWindow that this is indeed the main widget
setCentralWidget(m_view);
setupActions();
setupGUI();
}
当创建一个新的 AEmpireView(this)
时(继承自 QWidget
)并分配给 m_view,调用此构造函数:
AEmpireView::AEmpireView(QWidget *)
{
ui_aempireview_base.setupUi(this);
settingsChanged();
setAutoFillBackground(true);
}
因此,当我在 QT Designer 中编辑程序的 ui 时,我实际上正在编辑 AEmpireView_base
ui 文件,该文件是一个QWidget
。 它仅代表 KXmlGuiWindow
(派生自 QMainWindow
)的主视图,并在运行时加载。
那么,如何将可浮动、可拖动的 QDockWidget
添加到我的主应用程序中? 单独设计它们并将它们添加到 UI 中是最好的选择吗? 或者也许删除整个 AEmpireView 类,并使我的 ui 文件直接表示由 AEmpireClass 加载的 KXmlGuiWindow 对象?
或者我完全忽略了一些显而易见的事情? 谢谢阅读!
I'm just trying to get into QT (and KDE) program, and have hit a snag trying to add a floatable, draggable QDockWidget
to the .ui file (based as a QWidget
) that is embedded into my KDE 4 program.
This is all from the basic template provided by KDevelop 4, so while I understand what's going on, I just don't know the best way to change it.
Here's the deal: main.cpp spawns a new AEmpire
window, which starts the whole show off:
AEmpire::AEmpire()
: KXmlGuiWindow(),
m_view(new AEmpireView(this)),
m_printer(0)
{
// tell the KXmlGuiWindow that this is indeed the main widget
setCentralWidget(m_view);
setupActions();
setupGUI();
}
When a new AEmpireView(this)
is created (which inherits from QWidget
) and is assigned to m_view, this constructor is called:
AEmpireView::AEmpireView(QWidget *)
{
ui_aempireview_base.setupUi(this);
settingsChanged();
setAutoFillBackground(true);
}
So, when I am editing the ui to my program in QT Designer, I'm actually editing the AEmpireView_base
ui file, which is a QWidget
. It just represents the main view of the KXmlGuiWindow
(derived from QMainWindow
) and is loaded at runtime.
So, how do I add floatable, draggable QDockWidget
s into my main application? Is designing them separately, and add them to the UI the best option? Or maybe removing the entire AEmpireView
class, and making my ui file directly represent a KXmlGuiWindow
object to be loaded by the AEmpireClass
?
Or am I totally overlooking something obvious? Thanks for reading!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会将 QDockWidget 内容设计为单独的 UI 文件。 然后创建它们并将它们粘贴到 AEmpire 构造函数中的 QDockWidgets 中。
I would design the QDockWidget contents as separate UI files. Then create them and stick them into the QDockWidgets in the AEmpire constructor.