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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10598269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 14:15:31  来源:igfitidea点击:

How to change the Title of the window in Qt?

c++qtwindowtitle

提问by tna0y

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

如何在Qt中更改窗口的标题?(对于QDialogQMainWindow。)

回答by UmNyobe

void    QWidget::setWindowTitle ( const QString & )

EDIT: If you are using QtDesigner, on the property tab, there is an editable property called windowTitlewhich can be found under the QWidget section. The property tab can usually be found on the lower right part of the designer window.

编辑:如果您使用 QtDesigner,在属性选项卡上,有一个名为windowTitle的可编辑属性,可以在 QWidget 部分下找到。通常可以在设计器窗口的右下方找到属性选项卡。

回答by user1935257

For new Qt users this is a little more confusing than it seems if you are using QT Designer and .uifiles.

对于 Qt 新用户来说,这比使用 QT 设计器和.ui文件时看起来更令人困惑。

Initially I tried to use ui->setWindowTitle, but that doesn't exist. uiis not a QDialogor a QMainWindow.

最初我尝试使用ui->setWindowTitle,但这并不存在。 ui不是 aQDialog或 a QMainWindow

The owner of the uiis the QDialogor QMainWindow, the .uijust describes how to lay it out. In that case, you would use:

的所有者uiQDialogor QMainWindow.ui只是描述了如何布置它。在这种情况下,您将使用:

this->setWindowTitle("New Title");

I hope this helps someone else.

我希望这对其他人有帮助。

回答by bandito40

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.

我知道这是几年后的事,但我遇到了同样的问题。我找到的解决方案是更改 main.cpp 中的窗口标题。我想一旦w.show();被调用,窗口标题就不能再更改了。在我的情况下,我只希望标题反映当前目录并且它有效。

int main(int argc, char *argv[]) 
{
QApplication a(argc, argv);
MainWindow w;
w.setWindowTitle(QDir::currentPath());
w.show();

return a.exec();
}

回答by KingKong

You can also modify the windowTitleattribute in Qt Designer.

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

回答by Christian

system("title WhateverYouWantToNameIt");

回答by Harish Kumawat

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.setWindowTitle("Main Page");
    w.show();
    return a.exec();
}

enter image description here

在此处输入图片说明