How to change the Title of the window in Qt?

C++QtWindowTitle

C++ Problem Overview


How to change the title of the window in Qt? (Both for QDialog and QMainWindow.)

C++ Solutions


Solution 1 - C++

void 	QWidget::setWindowTitle ( const QString & )

EDIT: If you are using QtDesigner, on the property tab, there is an editable property called windowTitle which can be found under the QWidget section. The property tab can usually be found on the lower right part of the designer window.

Solution 2 - C++

For new Qt users this is a little more confusing than it seems if you are using QT Designer and .ui files.

Initially I tried to use ui->setWindowTitle, but that doesn't exist. ui is not a QDialog or a QMainWindow.

The owner of the ui is the QDialog or QMainWindow, the .ui just describes how to lay it out. In that case, you would use:

this->setWindowTitle("New Title");

I hope this helps someone else.

Solution 3 - C++

I know this is years later but I ran into the same problem. The solution I found was to change the window title in main.cpp. I guess once the w.show(); is called the window title can no longer be changed. In my case I just wanted the title to reflect the current directory and it works.

int main(int argc, char *argv[]) 
{
QApplication a(argc, argv);
MainWindow w;
w.setWindowTitle(QDir::currentPath());
w.show();

return a.exec();
}

Solution 4 - C++

You can also modify the windowTitle attribute in Qt Designer.

Solution 5 - C++

system("title WhateverYouWantToNameIt");

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiontna0yView Question on Stackoverflow
Solution 1 - C++UmNyobeView Answer on Stackoverflow
Solution 2 - C++user1935257View Answer on Stackoverflow
Solution 3 - C++bandito40View Answer on Stackoverflow
Solution 4 - C++KingKongView Answer on Stackoverflow
Solution 5 - C++ChristianView Answer on Stackoverflow