93

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

Mat
  • 202,337
  • 40
  • 393
  • 406
tna0y
  • 1,842
  • 3
  • 16
  • 33

5 Answers5

148
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.

Community
  • 1
  • 1
UmNyobe
  • 22,539
  • 9
  • 61
  • 90
  • 1
    Just for completeness here is it explained: qt-project.org/doc/qt-4.8/qwidget.html#windowTitle-prop – paul23 May 15 '12 at 10:02
  • 9
    I 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). – chacham15 Feb 23 '13 at 07: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. – Matthew Read Mar 27 '13 at 21:18
  • 2
    Maybe good to know: better put the "setWindowTitle()" at the end of the constructor – Wim May 06 '15 at 15:08
  • 1
    Is there a way to change font-family of the window title? Also can we make it appear bold? – Abhishek Agarwal Aug 01 '17 at 05:46
60

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.

BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
user1935257
  • 601
  • 1
  • 6
  • 4
  • 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. – Matthew Read Mar 27 '13 at 21:14
  • 5
    +1 for giving an example of actually implementing this in the code. – thnkwthprtls Apr 03 '14 at 15:33
  • Note that this method is not `protected` and can be called from outside the dialog class as well. – jrh Dec 11 '20 at 21:29
6

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();
}
bandito40
  • 597
  • 1
  • 5
  • 15
3

You can also modify the windowTitle attribute in Qt Designer.

KingKong
  • 71
  • 2
-4
system("title WhateverYouWantToNameIt");
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Christian
  • 1
  • 1