views:

591

answers:

1

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 QDockWidgets 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!

+1  A: 

I would design the QDockWidget contents as separate UI files. Then create them and stick them into the QDockWidgets in the AEmpire constructor.

Parker