Automatically shrink text in a table like structure to fit widget size
-
Hello,
I've following problem. I have a widget that has some data in form of a table on it.
At the moment its just a QGridLayout with QLabels on it, but it really does not matter how it is implemented if there is a better way.Now I want the widget to behave in a way, that if the widget size is getting too small for the text, the textsize will be reduced so it fits to the widget again.
I've found some examples with looping around and measuring with QFontMetrics and so on, however all these approaches seem kind of extremely complicated for just having a table that will scale the text to fit.
So is there a easy way to achieve such a basic behavior?
-
@JonB thanks for the reply. The problem in my case is, that if i e.g. do the font metrics for all the labels this leads to some oscillating of the widgets since they trigger each others resize events and keep going forever.
So this is not really an option.
Would somethink like a graphics szene maybe work where the whole widget is rendered first so everything fits and then the rendered image is scaled down to the widgets space??I even had some opengl widget for the task which was kind of worked, but its really a stupid solution and there must be some better way to get this running,
-
Hi,
Why not use a QTableView for that ?
-
@gde23 said in Automatically shrink text in a table like structure to fit widget size:
@JonB thanks for the reply. The problem in my case is, that if i e.g. do the font metrics for all the labels this leads to some oscillating of the widgets since they trigger each others resize events and keep going forever.
Yep, been in that kind of situation elsewhere. Painful :)
-
Sorry, my answer was incomplete. You would need a custom QStyledItemDelegate that does the computation. What I wanted to point is that it might be easier to achieve with that setup.