Solved Layout issues
-
@Cobra91151 you're right, its becaus eof the buttons
To continue with your current solution:
Pack all "Top VBoxLayouts" into a HBoxlayout and add that layout with the
appSettingsButtonLayout
to a VBoxLayout. -
Thank you very much. One more bug:
These issues is also when changing languages.
Current font:
I use default font -MS Shell Dlg 2
withsetPixelSize(15);
Maybe I need to set another font? What font is suitable for windows app development?
-
@Cobra91151 I would say this isn't a bug - there is just not enough space for this long check box text. You should use two columns instead of three.
-
This is not an option. I need three columns.
-
@Cobra91151 Then you need more space, or smaller font, or shorter text...
-
Ok. So what font family do you suggest to be suitable for windows app development?
-
@Cobra91151 Instead of lowering your font, why don't use just use your space better?
You can use 1 column for instance with separators or group boxes to denote different sections. You could use 2 columns.
One of the easiest changes that would solve your problems is getting rid of the listbox on the left and making those tabs on the top. Same effect, literally saves 25% of your horizontal space.
Also I noticed you are using addStretch now in places where I think you meant to use addSpacing. Stretch are growable blocks with a minimum size of the number you pass in. So 1 is usually plenty for a stretch, even 0 is fine (the default). If you want controllable spacing you want to use addSpacing().
-
@Cobra91151 I will not suggest any fonts. You should use the default. You should really consider to change your layout instead of hacking around with fonts until it somehow fits.
-
Personally, when I'm in a situation like you are, I go with a clipped Text and an info tooltip.
Here an example for a QLabel:
void setTextToLabel(QLabel *label, const QString text) { QFontMetrics metrix(label->font()); int width = label->width() - 2; QString clippedText = metrix.elidedText(text, Qt::ElideRight, width); label->setText(clippedText); if(text == clippedText) label->setToolTip(""); else label->setToolTip(text); }
-
Thanks for the suggestion. I will try it and reply.
-
Thanks. I have modified your function to get not only
QLabel
but allQWidgets
. I post it here so others can find a solution.Code:
QString clipWidgetText(QWidget *widget, const QString widgetText, int subtractPixelSize) { QFontMetrics fontMetrics(widget->font()); int widgetWidth = widget->width() - subtractPixelSize; QString clippedText = fontMetrics.elidedText(widgetText, Qt::ElideRight, widgetWidth); return clippedText; }
Usage:
QCheckBox *checkBox1 = new QCheckBox("Some long text", this) checkBox1->setText(clipWidgetText(checkBox1, checkBox1->text(), 5);
Thanks to all. I have fixed all layout issues.