How to change the title of the window in Qt? (Both for QDialog
and QMainWindow
.)
5 Answers
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.
-
1Just for completeness here is it explained: qt-project.org/doc/qt-4.8/qwidget.html#windowTitle-prop– paul23Commented May 15, 2012 at 10:02
-
10I dont know about other people, but stackoverflow is becoming a very useful documentation alternative, google often points me here before the actual documentation (and its also easier to read). Commented Feb 23, 2013 at 7:17
-
2@chacham15 The Qt documentation is quite good and very easy to read. SO doesn't even come close for simple what-is-the-function-name questions; we do better at slightly more complicated problems. Commented Mar 27, 2013 at 21:18
-
2Maybe good to know: better put the "setWindowTitle()" at the end of the constructor– WimCommented May 6, 2015 at 15:08
-
1Is there a way to change font-family of the window title? Also can we make it appear bold? Commented Aug 1, 2017 at 5:46
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.
-
1@UmNyobe The code generated from that .ui file will call
Owner->setWindowTitle()
, so it's no different. If you want the window title to be dynamic, you'd do it this way rather than in the .ui file. Commented Mar 27, 2013 at 21:14 -
6+1 for giving an example of actually implementing this in the code. Commented Apr 3, 2014 at 15:33
-
Note that this method is not
protected
and can be called from outside the dialog class as well.– jrhCommented Dec 11, 2020 at 21:29
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();
}
system("title WhateverYouWantToNameIt");
-
1
-
While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. Commented May 28, 2017 at 0:32
-
3Does this work? Is this even Qt? I never heard of this function.– jrhCommented Dec 11, 2020 at 21:29