Results 1 to 9 of 9

Thread: Repositioning widgets in QGridLayout

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Third rock from the sun
    Posts
    106
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    17
    Thanked 6 Times in 6 Posts

    Question Repositioning widgets in QGridLayout

    I am trying to create a dynamic (read: at runtime) layout for some custom plots, using a QGridLayout. On initialization, a single plot is displayed. The user selects to add other plots through menus, changing the overall layout. Adding the first object works fine, however adding the second object causes the first object to occupy/span both widgets with the second object in the correct position. Each subsequent object added is in the correct position, but the first object still spans the entire layout (can "see" the widget in the grid spacing/background).
    Qt Code:
    1. void RawDataWindow::layoutPlots()
    2. {
    3. QWidget *ui_plotAreaWidget = qFindChild<QWidget*>( this, "plotAreaWidget" );
    4. QGridLayout *plotLayout = (QGridLayout*) ui_plotAreaWidget->layout();
    5.  
    6. // Remove all plots from the layout to adjust spacing and setup reparenting
    7. for( int p = 0; p < mPlots.count(); p++ )
    8. {
    9. plotLayout->removeWidget( mPlots.at( p ).plotObject );
    10. mPlots.at( p ).plotObject->setParent( 0 );
    11. }
    12.  
    13. if( mPlots.count() == 1 )
    14. {
    15. plotLayout->addWidget( mPlots.at( 0 ).plotObject );
    16. }
    17. else if( mPlots.count() == 2 )
    18. {
    19. // Create a 1x2 grid
    20. plotLayout->addWidget( mPlots.at( 0 ).plotObject, 0, 0 );
    21. plotLayout->addWidget( mPlots.at( 1 ).plotObject, 0, 1 );
    22. }
    23. else if( mPlots.count() == 3 )
    24. {
    25. // 2x2 grid with the top plot spanning across both columns
    26. plotLayout->addWidget( mPlots.at( 0 ).plotObject, 0, 0, 1, 2 );
    27. plotLayout->addWidget( mPlots.at( 1 ).plotObject, 1, 0 );
    28. plotLayout->addWidget( mPlots.at( 2 ).plotObject, 1, 1 );
    29. }
    30. else if( mPlots.count() == 4 )
    31. {
    32. // 2x2 grid
    33. plotLayout->addWidget( mPlots.at( 0 ).plotObject, 0, 0 );
    34. plotLayout->addWidget( mPlots.at( 1 ).plotObject, 0, 1 );
    35. plotLayout->addWidget( mPlots.at( 2 ).plotObject, 1, 0 );
    36. plotLayout->addWidget( mPlots.at( 3 ).plotObject, 1, 1 );
    37. }
    38. }
    To copy to clipboard, switch view to plain text mode 

    I believe this is causing further issues in that whichever object I add last does not recieve mousePress/Release/Move events, but this is just speculation until I resolve the layout issue.

    Any ideas?

    Windows 7
    VS 2008
    Qt 4.6.3
    Last edited by Rayven; 17th March 2011 at 18:58.
    Every little child knows
    if you cant see dreams
    your eyes are blind

    Moxy Fruvous

Similar Threads

  1. Replies: 2
    Last Post: 16th December 2010, 12:52
  2. Function for repositioning the file pointer
    By psantofe in forum Qt Programming
    Replies: 7
    Last Post: 9th September 2010, 14:36
  3. Widgets in QGridLayout placed at top left
    By anarion in forum Newbie
    Replies: 2
    Last Post: 2nd September 2010, 16:06
  4. qgridlayout and hiding widgets
    By Michael_Levin in forum Newbie
    Replies: 3
    Last Post: 21st May 2010, 18:47
  5. space between widgets in qgridlayout
    By demol in forum Qt Programming
    Replies: 2
    Last Post: 6th January 2010, 21:07

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.