c++ - setWindowFilePath 在 Qt 中根本不起作用

标签 c++ qt title titlebar

为什么 setWindowFilePath 不起作用?插槽正在工作。窗口标题不会改变。 我的操作系统是Windows 7,Qt是用wchar_t支持编译的。

test::test(QWidget *parent, Qt::WFlags flags)
    : QMainWindow(parent, flags)
{
  ui.setupUi(this);
  QObject::connect(ui.pushButton, SIGNAL(clicked()), SLOT(Click()));
  setWindowTitle("Title");
}

void test::Click()
{
  setWindowFilePath("file.txt");
}

最佳答案

也许你的问题是你已经使用了 setWindowTitle()使用前setWindowFilePath() 。来自 docs :

If the window title is set at any point, then the window title takes precedence and will be shown instead of the file path string.

编辑:我刚刚尝试使用 setWindowFilePath()并注意到,只有在调用 show() 之后调用它,它才会生效。 。由于文档中没有提到这一点,所以它闻起来像一个错误......

编辑:好吧,如果不使用 setWindowTitle() 就无法工作。或调用setWindowFilePath()调用show()后,我不知道你的问题是什么。我做了一个工作示例,希望这可以帮助您找到问题:

#include <QApplication>
#include <QMainWindow>
#include <QPushButton>

class MyWindow : public QMainWindow
{
        Q_OBJECT

    public:

        MyWindow()
        {
            QPushButton* b = new QPushButton("Click me", this);
            connect(b, SIGNAL(clicked()), this, SLOT(click()));
        }

    private Q_SLOTS:

        void click()
        {
            setWindowFilePath("file.txt");
        }
};

int main(int argc, char* argv[])
{
    QApplication app(argc, argv);

    MyWindow w;
    w.show();

    return app.exec();
}

#include "main.moc"

关于c++ - setWindowFilePath 在 Qt 中根本不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4624201/

相关文章:

Qt双免费或损坏

android - 如何从带有对话框主题的扩展 ActionBarActivity 或 AppcompatActivity 的 Activity 中删除标题栏

python - Tkinter : How to center the window title

c++ - 在非VS项目中包含VS DLL

c++ - 在 C++ 中禁用隐式 this

c++ - 在 AIX 上编译 boost 示例程序

c++ - 使用 std::views 进行模板类型推断

Qt Creator 中函数的 C++ 注释

jquery - 有没有更有效的方法在页面标题中显示未读消息数?

c++ - Protocol Buffer : Understanding the compiled output of proto files