Results 1 to 3 of 3

Thread: Make column widths equal when concatenating 2 QGridLayouts

  1. #1
    Join Date
    Jan 2016
    Posts
    1
    Thanks
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Make column widths equal when concatenating 2 QGridLayouts

    I have an application which uses QGridLayout, and often can require 200 to 300 rows. We found layout issues (i.e. the widget would not render) when attempting to use that many rows; QGridLayout appears to have a limit of around 100 rows. We never found a way around that issue, so we append a new QGridLayout when the prior one reaches 100 rows. The problem is that the first gridlayout has a header row which is driving the column width. The appended gridlayouts don't have that header row, therefore their column widths do not match those of the first gridlayout.

    I tried the following approach to synchronize the column widths:
    Qt Code:
    1. auto oldGridLayout = qobject_cast<QGridLayout *>(m_gridLayouts.at(static_cast<unsigned>(m_gridLayouts.size() - 2)));
    2. auto newGridLayout = qobject_cast<QGridLayout *>(m_gridLayouts.at(static_cast<unsigned>(m_gridLayouts.size() - 1)));
    3. for (int i = 0; i < oldGridLayout->columnCount(); i++) {
    4. auto oldLayoutItem = oldGridLayout->itemAtPosition(0, i);
    5. auto newLayoutItem = newGridLayout->itemAtPosition(0, i);
    6. newLayoutItem->setGeometry(oldLayoutItem->geometry());
    7. }
    To copy to clipboard, switch view to plain text mode 

    The above approach did not work. Investigating a bit more, geometry().width() was not giving an accurate value. Perhaps I was queering prior to the widget had enough knowledge about itself (i.e. not fully rendered), but I don't see a different approach since both widgets are rendered in the same event.

    The app using these appended gridlayouts is stable and not much will be spent on it for future improvements. I'm hoping to find a solution which won't involve major surgery. Any suggestions appreciated.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Make column widths equal when concatenating 2 QGridLayouts

    If you are doing this in the constructor, then the sizes will not be correct yet. It needs to be done usually in the resize event (when the widget is visible - isVisible() returns true or after a showEvent() has occurred). Multiple resize events can occur before a widget is first shown, as the layout manager goes through the initial window layout calculations. Your algorithm might also be getting messed up if there are "stretch" elements that automatically resize grid cells based on content.

    Don't know your application, but it would seem that a table view / widget with appropriate delegates might be a better solution than massive grid layouts. But this is likely a "major surgery" scenario.

  3. The following user says thank you to d_stranz for this useful post:

    weavez (19th January 2016)

  4. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Make column widths equal when concatenating 2 QGridLayouts


  5. The following 2 users say thank you to anda_skoa for this useful post:

    d_stranz (19th January 2016), weavez (19th January 2016)

Similar Threads

  1. [Solved] Synchronizing column widths between QTableViews
    By Phlucious in forum Qt Programming
    Replies: 0
    Last Post: 7th March 2013, 01:17
  2. Greater or equal than and smaller or equal than not working..
    By ruben.rodrigues in forum General Programming
    Replies: 3
    Last Post: 27th April 2011, 09:09
  3. Saving QTableView Column Widths
    By stefanadelbert in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2010, 17:23
  4. Dynamic Sizing of QTableView Column Widths
    By tntcoda in forum Qt Programming
    Replies: 1
    Last Post: 17th June 2009, 19:30
  5. auto resizing column/row widths
    By raman_31181 in forum Qt Programming
    Replies: 2
    Last Post: 11th September 2008, 19:16

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.