Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Layout issues



  • @jsulm

    Ok. So what font family do you suggest to be suitable for windows app development?


  • Moderators

    @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().


  • Qt Champions 2019

    @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.


  • Moderators

    @Cobra91151

    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);
        }
    


  • @J.Hilk

    Thanks for the suggestion. I will try it and reply.



  • @J.Hilk

    Thanks. I have modified your function to get not only QLabel but all QWidgets . 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.


Log in to reply