简体   繁体   English

如何在Qt中更改窗口的标题?

[英]How to change the Title of the window in Qt?

How to change the title of the window in Qt?如何在Qt中更改窗口的标题? (Both for QDialog and QMainWindow .) (对于QDialogQMainWindow 。)

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.编辑:如果您使用 QtDesigner ,在属性选项卡上,有一个名为windowTitle的可编辑属性,可以在 QWidget 部分下找到。 The property tab can usually be found on the lower right part of the designer window.通常可以在设计器窗口的右下方找到属性选项卡。

For new Qt users this is a little more confusing than it seems if you are using QT Designer and .ui files.对于新的 Qt 用户来说,这比使用 QT Designer 和.ui文件时看起来更令人困惑。

Initially I tried to use ui->setWindowTitle , but that doesn't exist.最初我尝试使用ui->setWindowTitle ,但这并不存在。 ui is not a QDialog or a QMainWindow . ui不是QDialogQMainWindow

The owner of the ui is the QDialog or QMainWindow , the .ui just describes how to lay it out. ui的所有者是QDialogQMainWindow.ui只是描述如何布置它。 In that case, you would use:在这种情况下,您将使用:

this->setWindowTitle("New Title");

I hope this helps someone else.我希望这对其他人有帮助。

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.我找到的解决方案是更改 main.cpp 中的窗口标题。 I guess once the w.show();我猜一旦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();
}

您还可以在 Qt 设计器中修改windowTitle属性。

system("title WhateverYouWantToNameIt");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM