forked from mfreiholz/Qt-Advanced-Docking-System
-
Notifications
You must be signed in to change notification settings - Fork 663
Closed
Description
I have summarized the problem in the code below.
#include <QMainWindow>
#include "DockManager.h"
namespace Ui
{
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow( QWidget *parent = 0 );
~MainWindow();
public slots:
void doSomething();
private:
Ui::MainWindow *ui;
// The main container for docking
ads::CDockManager *m_DockManager;
};
MainWindow.h
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include <QLabel>
#include <QAction>
#include <chrono>
#include <thread>
MainWindow::MainWindow( QWidget *parent ) :
QMainWindow( parent ),
ui( new Ui::MainWindow )
{
ui->setupUi( this );
// Create the dock manager. Because the parent parameter is a QMainWindow
// the dock manager registers itself as the central widget.
m_DockManager = new ads::CDockManager( this );
// Add a do something action.
QAction *doSomethingAction = new QAction( "Do something" );
ui->menuAction->addAction( doSomethingAction );
connect( doSomethingAction, SIGNAL( triggered() ), this, SLOT( doSomething() ) );
// Create example content label - this can be any application specific
// widget
QLabel *l = new QLabel();
l->setWordWrap( true );
l->setAlignment( Qt::AlignTop | Qt::AlignLeft );
l->setText( "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. " );
// Create a dock widget with the title Label 1 and set the created label
// as the dock widget content
ads::CDockWidget *DockWidget = new ads::CDockWidget( "Label" );
DockWidget->setWidget( l );
// Add the toggleViewAction of the dock widget to the menu to give
// the user the possibility to show the dock widget if it has been closed
ui->menuView->addAction( DockWidget->toggleViewAction() );
// Add the dock widget to the top dock widget area
m_DockManager->addDockWidget( ads::TopDockWidgetArea, DockWidget );
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::doSomething()
{
std::chrono::milliseconds timespan( 1 );
for ( int i = 0; i != 2000; ++i )
{
std::this_thread::sleep_for( timespan );
// Take into account the events during the loop.
qApp->processEvents();
}
}
MainWindow.cpp
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget"/>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuView">
<property name="title">
<string>View</string>
</property>
</widget>
<widget class="QMenu" name="menuAction">
<property name="title">
<string>Action</string>
</property>
</widget>
<addaction name="menuView"/>
<addaction name="menuAction"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
MainWindow.ui
To reproduce the issue:
- Make the dock widget floating
- Click on the "do something" action, and immediately re-dock the floating widget within the main window
- See the floating container remains visible
- Later the container disappears.
"do something” enters a loop but it processes QApplication events (call to processEvents), so that GUI remains responsive.
After a closer look, it seems that the problem comes from the fact that the floating container is not destroyed manually when the widget is docked.
When the widget is redocked, looks like the floating container is requested to be deleted and this is done later by Qt.
Probably the floating container should be manually destroyed or at least hidden so that it disappears from screen waiting to be cleanly deleted by Qt ?
Thank you in advance
Metadata
Metadata
Assignees
Labels
No labels
