Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make KDDockWidgetsMainWindow work within another provided main window? #204

Closed
dlinenbe opened this issue Jun 12, 2021 · 6 comments
Closed

Comments

@dlinenbe
Copy link

dlinenbe commented Jun 12, 2021

How to make KDDockWidgetsMainWindow work within another provided main window?
I have another MainWindow provided by a component vendor, so I must use that.
I set the parent of KDDockWidgets::MainWindow to the other main window.
I then add this to a layout which is part of the CentralWidget.
I get what looks like a functional DockWidget -- but it is half broken. I cannot dock the widgets to each other or within the window. The docking indicator displays do not appear at all... The image shows the two widgets created successfully at the bottom of the screen (data1, data2), but moving the widgets around does not transmit events to the underlying main (I presume) - so the widgets are unaware of how to dock. How do I use KDDockWidget when a MainWindow is already provided? This is probably a common usage case. Picture & code follows as:

Capture

KDDockWidgets::MainWindow * dmw = new KDDockWidgets::MainWindow(QStringLiteral("KDDocker"), KDDockWidgets::MainWindowOption_None, this);
dmw->setFixedHeight(120);
{
auto dock = new KDDockWidgets::DockWidget(QStringLiteral("data1"));
auto* label = new QLabel(dock);
label->setText("1.1111");
label->setFont(QFont("Arial", 16));
dock->setWidget(label);
dock->show();
dmw->addDockWidget(dock, KDDockWidgets::Location_OnLeft);
}
{
auto dock = new KDDockWidgets::DockWidget(QStringLiteral("data2"));
auto* label = new QLabel(dock);
label->setText("22222.22");
label->setFont(QFont("Arial", 16));
dock->setWidget(label);
dock->show();
dmw->addDockWidget(dock, KDDockWidgets::Location_OnRight);
}
_WidgetSwitcher->_CentralWidgetVBoxLayout->addWidget(dmw);
dmw->show();
setCentralWidget(_WidgetSwitcher);

Thanks for any responses,
David Linenberg

@dlinenbe
Copy link
Author

Perhaps this is the same bug as issue #168.

@iamsergio
Copy link
Contributor

Can you modify examples/minimal/ then attach a .diff file here (or a link to your github with the change commited) ?

Then I can debug it quickly

@dlinenbe
Copy link
Author

dlinenbe commented Jun 13, 2021

Attached is a minimal file which creates a class derived from QMainWindow. Code is also copied/pasted.

That class holds another widget which contains a VBoxLayout which contains a KDDockWidgets::MainWindow with a number of DockWidgets. It renders the dockwidgets properly, but docking does not occur within the window. If I remove dockwidgets from the window, docking can occur in a floating window, but I cannot get the floating window back into the VBox

Test.txt

#include
#include
#include
#include
#include <kddockwidgets/DockWidget.h>
#include <kddockwidgets/MainWindow.h>

class Widget : public QWidget
{
public:
Widget(QWidget* parent = nullptr, Qt::WindowFlags flags = 0)
: QWidget(parent, flags)
{

    KDDockWidgets::MainWindow* dockMainWindow = new KDDockWidgets::MainWindow(QStringLiteral("KDDocker"), KDDockWidgets::MainWindowOption_None);
    dockMainWindow->setFixedHeight(500);
    for(int i = 1; i <= 5; ++i)
    {
        QString name = ("window_" + std::to_string(i)).c_str();
        auto dock = new KDDockWidgets::DockWidget(name);
        auto* label = new QLabel(dock);
        label->setText(name);
        dock->setWidget(label);
        dockMainWindow->addDockWidget(dock, KDDockWidgets::Location_OnLeft);
    }
    QVBoxLayout* vBoxLayout = new QVBoxLayout(this);
    vBoxLayout->addWidget(dockMainWindow);
}

};
class MainWindowTest : public QMainWindow
{
public:
MainWindowTest(QWidget* parent = nullptr, Qt::WindowFlags flags = 0)
: QMainWindow(parent, flags)
{
Widget* widget = new Widget(this);
setCentralWidget(widget);
show();
}
};
int main(int argc, char* argv[])
{
QApplication qApplication(argc, argv);
MainWindowTest mainWindowTest;
qApplication.exec();
return 0;
}`

@dlinenbe
Copy link
Author

dlinenbe commented Jun 13, 2021 via email

@dlinenbe dlinenbe reopened this Jun 14, 2021
@iamsergio
Copy link
Contributor

Fixed in 206433e

@dlinenbe
Copy link
Author

dlinenbe commented Jun 15, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants