r4ndom n00b
r4ndom n00b

Reputation: 99

How to set Windows taskbar title of a QMainWindow?

Out of curiosity: I am currently developing a Qt application on Windows 7. I want to set the window title to display in the taskbar. setWindowTitle is not applicable as my UI is a QMainWindow, not a QWidget.

I have a QString with the title, but I can't set it. I set the QMainWindow title in the Qt Designer but that's static. All I had reached is this:

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
  // ....
  QApplication::setApplicationDisplayName(qAppTitle);
  parent->setWindowTitle(qAppTitle);
  // ...
}

This turns the window title in my taskbar into:

[title from Qt Designer] - [qAppTitle variable]

Sucks.

Ideas?

Upvotes: 3

Views: 2756

Answers (1)

paulm
paulm

Reputation: 5882

QMainWindow has a setWindowTitle the same as QWidget (because it is one), see this question:

How to set QMainWindow title

Thus the solution is:

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
  setWindowTitle("Hello world");
}

http://doc.qt.digia.com/4.7/qwidget.html#windowTitle-prop

Also

http://qt-project.org/doc/qt-5.0/qtwidgets/qmainwindow.html

"QMainWindow Class

The QMainWindow class provides a main application window. More...
#include <QMainWindow>
Inherits: QWidget."

Upvotes: 2

Related Questions