Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Square custom QWidgets inside QGridLayout inside QScrollArea
Forum Updated to NodeBB v4.3 + New Features

Square custom QWidgets inside QGridLayout inside QScrollArea

Scheduled Pinned Locked Moved General and Desktop
scrollareagridlayoutsizepolicy
2 Posts 1 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    blashyrk
    wrote on 5 Jun 2015, 17:21 last edited by
    #1

    Hello,
    I'm trying to lay out a grid of square custom (subclassed) QWidgets inside a QGridLayout and QScrollArea.

    The way I want it to work is choosing the number of QGridLayout columns and creating squares of the correct sizes.

    What I've tried doing already is

    • Manually laying out/resizing the QWidgets but I feel this is a bit sloppy and I couldn't get it quite right
    • Setting QScrollArea::widgetsResized to true which does resize the width correctly, but not the height, see screenshot.

    I've tried setting QSizePolicy and overriding QWidget::heightForWidth along with setting QScrollArea::widgetsResized in my custom QWidget-derived class, like so:

    CustomWidget::CustomWidget(...) 
    {  
      ...
    
      QSizePolicy policy(QSizePolicy::Preferred, QSizePolicy::Preferred);
      policy.setHeightForWidth(true);
    
      setSizePolicy(policy);
    }
    
    ...
    
    int CustomWidget::heightForWidth(int width) const
    {
        return width; // square
    }
    

    But CustomWidget::heightForWidth is never called.

    Any help would be appreciated.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      blashyrk
      wrote on 6 Jun 2015, 10:02 last edited by
      #2

      Solution here if anyone runs into the same problem: http://stackoverflow.com/questions/30672183/square-custom-qwidgets-inside-qgridlayout-inside-qscrollarea

      1 Reply Last reply
      0

      1/2

      5 Jun 2015, 17:21

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved