Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Height-For-Width layouts and widgets #118

Open
jamesdbrock opened this issue Feb 28, 2024 · 1 comment
Open

Height-For-Width layouts and widgets #118

jamesdbrock opened this issue Feb 28, 2024 · 1 comment

Comments

@jamesdbrock
Copy link
Member

jamesdbrock commented Feb 28, 2024

Rudolf Cardinal appears to have a real solution for the Label layout problem.

https://stackoverflow.com/questions/14238138/heightforwidth-label

  • Rewrite the layouts.
  • The best approach I've found is to have layouts calculate their children's geometry assuming some sort of standard rectangle (Qt itself often starts with a 640x480 one when drafting a layout); offering height information based on this draft; then, when setGeometry() is called, if the resulting height (based on a potentially new width) doesn't match what the layout previously advertised, re-constraining by calling parent->setFixedHeight().
  • This allows you to use arbitrary widgets, and HFW widgets only need to support hasHeightForWidth() and heightForWidth() to have the new layouts (and their parent widgets, and any ancestor layouts using this mechanism) adjust their height.
  • It can lead to some redrawing, but often not too much, as it happens on a per-layout not per-widget basis.

I've put C++ code at http://egret.psychol.cam.ac.uk/code/2017_01_16_qt_height_for_width/ for the following layouts:

and the following widgets:

  • AspectRatioPixmapLabel -- image maintaining its aspect ratio;
  • LabelWordWrapWide -- word-wrapping label that tries to use as much horizontal space before it word-wraps.
  • VerticalScrollArea -- as its name suggests, a vertical scroll area, but one that supports height-for-width cleanly.

Those layout and widgets are at these paths

The CamCOPS authors have relicensed those layouts and widgets as LGPL ucam-department-of-psychiatry/camcops#340

So this would be a complete solution to Qt layout problem, but it would require a few steps.

  1. Create a new repository cardinal-qtwidgets for Shiboken Python bindings to all of those layouts and widgets. LGPL license. Depends on Qt.
  2. Create a new repository pyedifice-cardinal-elements for Edifice Base Elements for all of those layouts and widgets. Depends on Qt and cardinal-qtwidgets and pyedifice. LGPL license.
@jamesdbrock
Copy link
Member Author

jamesdbrock commented Feb 28, 2024

Would resolve #41

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant