How to change the Title of the window in Qt?
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.
Related videos on Youtube
Comments
-
tna0y almost 2 years
How to change the title of the window in Qt? (Both for
QDialog
andQMainWindow
.) -
paul23 about 12 yearsJust for completeness here is it explained: qt-project.org/doc/qt-4.8/qwidget.html#windowTitle-prop
-
chacham15 over 11 yearsI 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 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 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 about 10 years+1 for giving an example of actually implementing this in the code.
-
Wim about 9 yearsMaybe good to know: better put the "setWindowTitle()" at the end of the constructor
-
eyllanesc about 7 yearsYou should put a brief description of your answer.
-
Badacadabra about 7 yearsWhile 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 almost 7 yearsIs there a way to change font-family of the window title? Also can we make it appear bold?
-
jrh over 3 yearsNote that this method is not
protected
and can be called from outside the dialog class as well. -
jrh over 3 yearsDoes this work? Is this even Qt? I never heard of this function.