如何设置QMainWindow的Windows任务栏标题?(How to set Windows taskbar title of a QMainWindow?)

编程入门 行业动态 更新时间:2024-10-11 19:19:49
如何设置QMainWindow的Windows任务栏标题?(How to set Windows taskbar title of a QMainWindow?)

出于好奇:我目前正在Windows 7上开发一个Qt应用程序。我想设置窗口标题以显示在任务栏中。 setWindowTitle不适用,因为我的UI是QMainWindow ,而不是QWidget 。

我有一个标题的QString ,但我无法设置它。 我在Qt Designer中设置了QMainWindow标题但这是静态的。 我所达到的只是:

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { // .... QApplication::setApplicationDisplayName(qAppTitle); parent->setWindowTitle(qAppTitle); // ... }

这会将我的任务栏中的窗口标题变为:

[来自Qt Designer的标题] - [qAppTitle变量]

吮吸。

想法?

Out of curiosity: I am currently developing a Qt application on Windows 7. I want to set the window title to display in the taskbar. setWindowTitle is not applicable as my UI is a QMainWindow, not a QWidget.

I have a QString with the title, but I can't set it. I set the QMainWindow title in the Qt Designer but that's static. All I had reached is this:

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { // .... QApplication::setApplicationDisplayName(qAppTitle); parent->setWindowTitle(qAppTitle); // ... }

This turns the window title in my taskbar into:

[title from Qt Designer] - [qAppTitle variable]

Sucks.

Ideas?

最满意答案

QMainWindow有一个与QWidget相同的setWindowTitle(因为它是一个),请看这个问题:

如何设置QMainWindow标题

因此解决方案是:

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { setWindowTitle("Hello world"); }

http://doc.qt.digia.com/4.7/qwidget.html#windowTitle-prop

http://qt-project.org/doc/qt-5.0/qtwidgets/qmainwindow.html

"QMainWindow Class The QMainWindow class provides a main application window. More... #include <QMainWindow> Inherits: QWidget."

http://i41.tinypic.com/2zsbr45.png

QMainWindow has a setWindowTitle the same as QWidget (because it is one), see this question:

How to set QMainWindow title

Thus the solution is:

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { setWindowTitle("Hello world"); }

http://doc.qt.digia.com/4.7/qwidget.html#windowTitle-prop

Also

http://qt-project.org/doc/qt-5.0/qtwidgets/qmainwindow.html

"QMainWindow Class The QMainWindow class provides a main application window. More... #include <QMainWindow> Inherits: QWidget."

http://i41.tinypic.com/2zsbr45.png

更多推荐

本文发布于:2023-08-02 19:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1379843.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:任务栏   如何设置   标题   QMainWindow   title

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!