1

Is is possible to have labels in a QToolBar? Something like the green text I draw on top of the app screenshot.

I would like to have a set of actions in a toolbar, all them retated to some a system. Then another toolbar with another set of actions related to another system. So each toolbar would have a label named accordingly to the specific system.

enter image description here

QApplication a(argc, argv);
QMainWindow *w = new QMainWindow;

QToolBar *barA = new QToolBar;
barA->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);

QAction *actOnA = new QAction("OnA");
actOnA->setIcon(QIcon("../../../on.png"));
barA->addAction(actOnA);
QAction *actOffA = new QAction("OffA");
actOffA->setIcon(QIcon("../../../off.png"));
barA->addAction(actOffA);
w->addToolBar(barA);

QToolBar *barB = new QToolBar;
barB->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);

QAction *actOnB = new QAction("OnB");
actOnB->setIcon(QIcon("../../../on.png"));
barB->addAction(actOnB);
QAction *actOffB = new QAction("OffB");
actOffB->setIcon(QIcon("../../../off.png"));
barB->addAction(actOffB);
w->addToolBar(barB);

w->show();
return a.exec();

I think I saw similar labels in a Microsoft MFC project.

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
KcFnMi
  • 5,516
  • 10
  • 62
  • 136
  • How about you design a custom widget that contains both on/off icons and the subcaption. Then you can add the widget to a toolbar. – ypnos Sep 19 '19 at 11:30

1 Answers1

1

yes, you need to create your custom widget first and then do:

ui->statusBar->addWidget(MY_CUSTOM_WIDGEt);

e.g.

auto b = new QPushButton(this);
b->setText("hello");
connect(b, &QPushButton::clicked, [](){qDebug()<< "ok...";});
ui->statusBar->addWidget(b);
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97