How to change the Title of the window in Qt?

133,706

Solution 1

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

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

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

You can also modify the windowTitle attribute in Qt Designer.

Share:
133,706

Related videos on Youtube

tna0y
Author by

tna0y

MIPT Student https://github.com/tna0y

Updated on July 08, 2022

Comments

  • tna0y
    tna0y almost 2 years

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

  • paul23
    paul23 about 12 years
    Just for completeness here is it explained: qt-project.org/doc/qt-4.8/qwidget.html#windowTitle-prop
  • chacham15
    chacham15 over 11 years
    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).
  • Matthew Read
    Matthew Read over 11 years
    @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
    Matthew Read over 11 years
    @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.
  • thnkwthprtls
    thnkwthprtls about 10 years
    +1 for giving an example of actually implementing this in the code.
  • Wim
    Wim about 9 years
    Maybe good to know: better put the "setWindowTitle()" at the end of the constructor
  • eyllanesc
    eyllanesc about 7 years
    You should put a brief description of your answer.
  • Badacadabra
    Badacadabra about 7 years
    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.
  • Abhishek Agarwal
    Abhishek Agarwal almost 7 years
    Is there a way to change font-family of the window title? Also can we make it appear bold?
  • jrh
    jrh over 3 years
    Note that this method is not protected and can be called from outside the dialog class as well.
  • jrh
    jrh over 3 years
    Does this work? Is this even Qt? I never heard of this function.