Results 1 to 1 of 1

Thread: Autoscaling widget font on resize

  1. #1
    Join Date
    Jan 2014
    Posts
    36
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Autoscaling widget font on resize

    I'm trying to develop a container widget that will automatically recalculate font sizes of child widgets when the container & child widgets get resized. The purpose of this widget is that my application is being used in a laboratory environment where the users are often working on a remote device that communicates to my application in real-time. The remote device is often far enough from the host computer that they'd like to be able to increase the font size so that they can read the live data from where they're standing. I know I could do this with some sort of font dialog/spin box setup, but I thought it would be easier if the font size would automatically increase/decrease to fit the widget size(s) based on string length.

    The widget should basically function like an QHBoxLayout, keeping the child widgets in a horizontal row. The child widgets are a mix of QLabel, QRadioButton, QSpinBox, QCheckBox, QPushButton, QLineEdit. So I've reimplemented resizeEvent() for my container widget and am using QFontMetrics to determine what the largest font size is that will work based on the sizes of all the child widgets.

    I've got a functioning demo which I've attached, but it's got a couple of issues:
    1. Fonts/widgets gets bigger, but not smaller. When the application launches everything starts out 8 point (at least on my machine). When I drag the resize handles to make the main window larger the font size increases (yay!). But once the window has increased in size, there doesn't seem to be a way to drag the window smaller again; my container widget never gets any resize events when I'm trying to shrink the window. I'm assuming this is a QSizePolicy issue, but I think I've tried all of them and haven't got it to work the way I want. Ideally the container widget is willing to be as big or small as necessary, but always tries to make the font as large as possible, once all the child widget sizes have been calculated.
    2. For widgets that have non-text decorations (like the buttons in a QCheckBox or QRadioButton, etc.) there doesn't seem to be a way to query for the width (in pixels) of the text-only portion of that widget. QRadioButton::size() returns the pixel size of the entire widget (button + text label), which then screws up the calculations of how big the font can be based on string length since it thinks the available space for text is wider than it actually is.
    Attached Files Attached Files

Similar Threads

  1. Replies: 1
    Last Post: 4th July 2012, 20:09
  2. Replies: 5
    Last Post: 20th June 2012, 20:02
  3. How to resize parent widget when child widget is resized
    By ainne810329 in forum Qt Programming
    Replies: 4
    Last Post: 29th November 2011, 08:47
  4. How to resize label font to fit size
    By P@u1 in forum Qt Programming
    Replies: 2
    Last Post: 19th July 2011, 00:07
  5. Replies: 1
    Last Post: 2nd May 2010, 00:03

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.