Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-64132

QToolButton should elide text when width constraints prevent from showing whole text

XMLWordPrintable

    • b2a282d7c7b8f49819bbc86ed705980438ecb04b , 021906f6c (dev), 2376f6a2c (6.5), 1d01af306 (tqtc/lts-5.15), 017ebb2ed (tqtc/lts-6.2), 8be65ba91 (6.4)

      QToolButton will cut off text (details might depend on style) when maximum width will prevent it from allocating enough space, which looks ugly.
      At least some other widgets (like `QTabBar`) will elide text in such cases.
      Example code:

      #include <QtWidgets/QApplication>
      #include <QtWidgets/QBoxLayout>
      #include <QtWidgets/QToolButton>
      
      int main(int argc, char *argv[])
      {
      	QApplication application(argc, argv);
      	QWidget widget;
      	QToolButton normalToolButton(&widget);
      	normalToolButton.setIcon(QIcon::fromTheme("text-html"));
      	normalToolButton.setIconSize({64, 64});
      	normalToolButton.setText("Some Text");
      	normalToolButton.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
      
      	QToolButton constrainedToolButton(&widget);
      	constrainedToolButton.setIcon(QIcon::fromTheme("text-html"));
      	constrainedToolButton.setIconSize({64, 64});
      	constrainedToolButton.setText("Some Text");
      	constrainedToolButton.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
      	constrainedToolButton.setFixedWidth(64);
      
      	QBoxLayout layout(QBoxLayout::TopToBottom, &widget);
      	layout.addWidget(&normalToolButton);
      	layout.addWidget(&constrainedToolButton);
      
      	widget.show();
      
      	return application.exec();
      }
      

      Related URL:
      https://bugs.kde.org/show_bug.cgi?id=386076

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            chehrlic Christian Ehrlicher
            emdek MichaƂ Dutkiewicz
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: