Results 1 to 2 of 2

Thread: Widget with fixed aspect ratio

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Widget with fixed aspect ratio

    Hi,

    I'm trying to get two QWidget derived classes that need to mantain a "forced" aspect ratio.

    The first widget class must be "square" as I need to display a circle inside it.

    The second widget will contain a set of this first widget class with some rows and some columns.

    On the attached image you can see what I want to achieve.Image001.jpg

    The first widget class is the widget that displays a green circle with a text inside. The second widget is the "container" widget that includes the set of this first class widget into rows and columns. There is also a widget that the only thing that it do is to get space and so I can get "displacement" as I need the fist class widgets to be disposed in the way that you can see on the attached image.

    Can someone point me on how to achieve this?

    What I have tryied is to create a QGridLayout derived class that reimplements "hasHeightForWidth" and "heightForWidth" with no luck.


    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Oct 2014
    Posts
    81
    Thanks
    20
    Thanked 9 Times in 9 Posts
    Qt products
    Qt5
    Platforms
    Windows
    Wiki edits
    7

    Default Re: Widget with fixed aspect ratio

    You need to post your code, just to eliminate the chance that it's something obvious that you're missing.

    Note that QWidget also has these functions. Can you give them a try?
    http://doc.qt.io/qt-5/qwidget.html#hasHeightForWidth

    EDIT: actually, I think the layout of the container will be querying this from the layout items. So you should subclass QLayoutItem and use QLayout::addItem or QBoxLayout::insertItem etc. to add your QLayoutItem derived objects that return 'true' for that ratio function, and the height etc.
    The default implementation of the layout items ignores the setting:
    http://code.qt.io/cgit/qt/qtbase.git...titem.cpp#n368

    You would use this just for the circle widgets. The container widget will be sized according to its contents.
    For the empty spaces, the layouts let you add spacers:
    http://doc.qt.io/qt-5/qspaceritem.html#details
    Last edited by Kryzon; 19th October 2015 at 21:27.

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

    ^NyAw^ (23rd October 2015)

Similar Threads

  1. Replies: 7
    Last Post: 18th November 2016, 12:48
  2. QCameraViewfinder aspect ratio
    By gpuckett in forum Qt Programming
    Replies: 0
    Last Post: 29th May 2014, 20:52
  3. QSvgWidget cannot set fixed aspect ratio
    By gnetscher in forum Qt Programming
    Replies: 2
    Last Post: 6th August 2012, 14:51
  4. Printing and Aspect ratio
    By cpt4 in forum Qwt
    Replies: 9
    Last Post: 30th September 2011, 15:28
  5. Replies: 2
    Last Post: 20th April 2011, 13:47

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.