Solved scaledContents Equivalent for QComboBox
-
As I have been working on my application I've noticed many of the text elements in widgets (e.g. QComboBox, QPushButton...) don't resize if the window resizes.
For example, when my application initially runs it's smaller than my screen size. When I maximize the application, the window is exactly the size of my screen, and the widgets resize & adjust accordingly, but the font/ text remains the same size.
QLabel has the "scaledContents(bool)" property. From the doc, I believe this is exactly what I need, but for QComboBox.
Is there anything that is similar or will produce the same result for QComboBox that scaledContents(bool) does for QLabel? How can I adjust the size of the font/ text when the widget resizes?
-
Hi
Sadly no.
Qt has font scaling when using different DPI screens
http://doc.qt.io/qt-5/highdpi.html
but Qt will not adjust the point size on resizing the parent window.
If you wish to have say a combobox use more width, you have to use something like
QFontInfo to calculate manually a new font point size for it to use. -
That is interesting. I can't help but think that Qt has some way of accomplishing this.
Maybe this example will help:
In the image below, the text "Down The Rabbit Hole I Go" has a size; lets call it X. This window is not in Maximized mode.
Now in this image, the same text seems to have a smaller size than X. This window is in Maximized mode.
So, when the window is maximized, the text adjusts to the new dimensions. This is similar to what I am trying to accomplish.
-
Hi
Well its possible to calculate your self and adjust the font for the combo box.
However, its purely manual code.