PDA

View Full Version : layout refresh problem



Alundra
15th June 2014, 03:20
Hi all,
I have a layout with multiple widget on a widget, it's a path bar like windows explorer.
When I change folder, I change the layout with the new path who is a layout of button.
The problem is I have bad result when I change folder, it's like a reresh problem, I have the old text on the new text.


void CContentBrowserPathWidget::UpdatePath()
{
// Get the layout and delete if not NULL.
if( m_Layout != NULL )
delete m_Layout;

// Create the layout.
m_Layout = new QHBoxLayout;
m_Layout->setSpacing( 0 );
m_Layout->setMargin( 0 );
setLayout( m_Layout );

// Cast the model.
QFileSystemModel* Model = static_cast< QFileSystemModel* >( m_TreeView->model() );

// Get the root path.
const QString RootPath = Model->rootPath();

// Add the root.
m_Layout->addWidget( new CPathButton( "" ) );

// Check if the current index is invalid.
if( m_TreeView->currentIndex().isValid() == false )
return;

// Get the current path.
const QString CurrentPath = Model->filePath( m_TreeView->currentIndex() );

// Check if the current path is different than the root.
if( CurrentPath != RootPath )
{
QString RightPath = CurrentPath;
RightPath.remove( RootPath + '/' );
const QStringList FolderList = RightPath.split( '/' );
for( int i = 0; i < FolderList.size(); ++i )
m_Layout->addWidget( new CPathButton( FolderList[ i ] ) );
}
}

Thanks for the help

Alundra
15th June 2014, 20:02
Apparently, it's better to delete then recreate the widget than update the layout, the problem is removed.