Label in a QToolbar
Asked Answered
T

3

8

How would you suggest to add a label on a QToolbar ? Since it only accepts action or somethings like that.

Thx

Tinware answered 9/4, 2012 at 21:0 Comment(0)
L
12

The QToolBar also accepts widgets like a QLabel through the method QToolBar::addWidget.

Lowrance answered 9/4, 2012 at 21:56 Comment(0)
C
17

As abresas wrote, a toolbar can be populated with a QAction. The QString passed along with the QAction is used in several ways (e.g as tooltip), but with 4.8 the default is to show a toolbar button with the icon only. To show the text with the icon, set the toolbar to a Qt::ToolButtonStyle, e.g.

ui->toolBar->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
Corrigible answered 30/11, 2012 at 8:53 Comment(2)
I had to do ui->mainToolBar->setToolButtonStyle( Qt::ToolButtonTextUnderIcon ); in Qt 5.4Topeka
strangely enough the text shows up tripped in the bottom for long characters like 'g'. Any idea why that might be?Topeka
L
12

The QToolBar also accepts widgets like a QLabel through the method QToolBar::addWidget.

Lowrance answered 9/4, 2012 at 21:56 Comment(0)
S
-2

You just pass the string to addAction method.

http://doc.qt.io/qt-5/qtoolbar.html

QAction *   addAction ( const QString & text )
Szymanski answered 9/4, 2012 at 21:2 Comment(1)
If you do it like this then it is also a buttonTebet

© 2022 - 2024 — McMap. All rights reserved.