Results 1 to 2 of 2

Thread: layout refresh problem

  1. #1
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Exclamation layout refresh problem

    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.
    Qt Code:
    1. void CContentBrowserPathWidget::UpdatePath()
    2. {
    3. // Get the layout and delete if not NULL.
    4. if( m_Layout != NULL )
    5. delete m_Layout;
    6.  
    7. // Create the layout.
    8. m_Layout = new QHBoxLayout;
    9. m_Layout->setSpacing( 0 );
    10. m_Layout->setMargin( 0 );
    11. setLayout( m_Layout );
    12.  
    13. // Cast the model.
    14. QFileSystemModel* Model = static_cast< QFileSystemModel* >( m_TreeView->model() );
    15.  
    16. // Get the root path.
    17. const QString RootPath = Model->rootPath();
    18.  
    19. // Add the root.
    20. m_Layout->addWidget( new CPathButton( "" ) );
    21.  
    22. // Check if the current index is invalid.
    23. if( m_TreeView->currentIndex().isValid() == false )
    24. return;
    25.  
    26. // Get the current path.
    27. const QString CurrentPath = Model->filePath( m_TreeView->currentIndex() );
    28.  
    29. // Check if the current path is different than the root.
    30. if( CurrentPath != RootPath )
    31. {
    32. QString RightPath = CurrentPath;
    33. RightPath.remove( RootPath + '/' );
    34. const QStringList FolderList = RightPath.split( '/' );
    35. for( int i = 0; i < FolderList.size(); ++i )
    36. m_Layout->addWidget( new CPathButton( FolderList[ i ] ) );
    37. }
    38. }
    To copy to clipboard, switch view to plain text mode 
    Thanks for the help

  2. #2
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: layout refresh problem

    Apparently, it's better to delete then recreate the widget than update the layout, the problem is removed.

Similar Threads

  1. Refresh problem with QPaintEvent
    By rawfool in forum Newbie
    Replies: 10
    Last Post: 23rd April 2013, 15:39
  2. QComboBox refresh problem
    By waynew in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2011, 13:30
  3. Replies: 2
    Last Post: 14th January 2011, 16:09
  4. QWidget Refresh Problem
    By MarkoSan in forum Qt Programming
    Replies: 2
    Last Post: 15th January 2008, 12:24
  5. QTableView refresh problem
    By tebessum in forum Qt Programming
    Replies: 3
    Last Post: 29th December 2006, 12:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.