PDA

View Full Version : Flickering custom titlebar



Alundra
17th January 2015, 20:23
Hi all,
I have a class inherited from QDockWidget to set a custom titlebar in the constructor (to avoid to set each time).
All works good but when I have the QMainWindow loading I have flickering each time a dock is added.
If I use just a QDockWidget, not my custom class with titlebar, I don't see the flickering at all.
Here the code of the custom dock widget, CTitlebarWidget uses parent() to access the dock.


CDockWidget::CDockWidget( const QString& Title, QWidget* Parent ) :
QDockWidget( Title, Parent )
{
m_Titlebar = new CTitlebarWidget( this );
setTitleBarWidget( m_Titlebar );
}

bool CDockWidget::event( QEvent* event )
{
switch( event->type() )
{
case QEvent::WindowTitleChange :
{
m_Titlebar->SetTitle( windowTitle() );
return true;
}

case QEvent::NonClientAreaMouseButtonDblClick :
{
if( isMaximized() )
showNormal();
else
showMaximized();
return true;
}
}
return QDockWidget::event( event );
}

Why flickering is visible ? There are visible only on loading.
That's like if dock is floating for a little time.
Thanks for the help

Kryzon
23rd January 2015, 22:52
Have you tried creating all of the dock widgets (custom or otherwise) with the QMainWindow hidden, and only after everything is created calling mainWindow.show()?

Alundra
23rd January 2015, 23:50
Gives the same result using that :


CMainEditorWindow::CMainEditorWindow()
{
hide();
...
...
}

All my dock use the custom QDockWidget to have the custom title bar, if I change all using QDockWidget from Qt I don't have flickering.

Kryzon
24th January 2015, 00:32
I meant creating your docks and setting their custom title bars before the absolute first call to QMainWindow.show() in your program.
QMainWindow is hidden at the moment you create it, so it's possible that it will hide that flickering if you prepare your widgets while it's like this.

Alundra
24th January 2015, 01:53
Apparently the problem of flickering is because the widget created in the TitleBarWidget constructor doesn't use "this" as parent, using "this" the flickering is out but my layout is now not good visually, I have to find how recode it to be like before. I tried a QLinedEdit as titlebar and I saw the flickering was out, like that I found the answer.
EDIT:
SOLVED, but I need something tell me if that's correct. I have all widget using "this" as parent but the layout has no parent, then I use at the end "setLayout( Layout );".
setLayout set the layout to the new parent or a memory leak is present ?
EDIT:
Apparently the doc do like I do :
http://doc.qt.io/qt-5/qwidget.html#setLayout
All looks ok