99

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

5 Answers 5

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

5
  • 1
    Just for completeness here is it explained: qt-project.org/doc/qt-4.8/qwidget.html#windowTitle-prop
    – paul23
    Commented May 15, 2012 at 10:02
  • 10
    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
    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
  • 2
    Maybe good to know: better put the "setWindowTitle()" at the end of the constructor
    – Wim
    Commented May 6, 2015 at 15:08
  • 1
    Is 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
66

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.

3
  • 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.
    – jrh
    Commented Dec 11, 2020 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();
}
3

You can also modify the windowTitle attribute in Qt Designer.

-4
system("title WhateverYouWantToNameIt");
3
  • 1
    You should put a brief description of your answer.
    – eyllanesc
    Commented May 27, 2017 at 15:37
  • 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
  • 3
    Does this work? Is this even Qt? I never heard of this function.
    – jrh
    Commented Dec 11, 2020 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.