简体   繁体   English

"从 Qt 窗口中删除标题栏,同时保留默认窗口边框"

[英]Removing titlebar from Qt window while keeping the default window borders

I'm trying to remove the default Windows titlebar from my Qt window (QT version 5.12.2 and using C++) while still keeping the window borders.我正在尝试从我的 Qt 窗口(QT 版本 5.12.2 并使用 C++)中删除默认的 Windows 标题栏,同时仍保留窗口边框。 I've more or less achieved this using the flag Qt::CustomizeWindowHint<\/code> .我使用标志Qt::CustomizeWindowHint<\/code>或多或少地实现了这一点。 However, this changes the window borders to white lines instead of the default borders.但是,这会将窗口边框更改为白线,而不是默认边框。

Example of how the borders look AFTER I've applied the Qt::CustomizeWindowHint<\/code> flag:应用Qt::CustomizeWindowHint<\/code>标志后边框的外观示例: 在此处输入图像描述<\/a>

As you can see, these are not the normal Windows window borders.如您所见,这些不是正常的 Windows 窗口边框。

How can I change\/edit these boders (ie change their color) or how am I able to keep the default Windows window borders while removing the titlebar?如何更改\/编辑这些边框(即更改它们的颜色)或如何在删除标题栏的同时保留默认的 Windows 窗口边框?

Here's a minimal reproducible example:这是一个最小的可重现示例:

main.cpp:主.cpp:

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

    QApplication application(argc, argv);
    launcher mainWindow;

    //debugChecks();
    mainWindow.setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::MSWindowsFixedSizeDialogHint);
    mainWindow.setWindowTitle("Test");
    mainWindow.show();

    return application.exec();
}
QPalette and QStyle for Border

Your description isn't really clear.你的描述不是很清楚。 One should not be using a QMainWindow for a logon\/in dialog.不应将 QMainWindow 用于登录\/登录对话框。 Having said that I created an application on Ubuntu 20.04 (should build fine for you as I used qmake).话虽如此,我在 Ubuntu 20.04 上创建了一个应用程序(应该为您构建良好,因为我使用了 qmake)。 You can download the project zip here<\/a> .您可以在此处下载项目 zip<\/a> 。 When the application starts it looks like this:当应用程序启动时,它看起来像这样:

在此处输入图像描述<\/a>

After clicking on "golden" it looks like this:点击“金色”后,它看起来像这样:

在此处输入图像描述<\/a>

After Green it looks like this:在绿色之后它看起来像这样:

在此处输入图像描述<\/a>

After clicking on Freaky it looks like this:单击 Freaky 后,它看起来像这样:

在此处输入图像描述<\/a>

Please note that FramelessWindowHint not only removes the title bar and system menu along with window frame, it also removes your ability to resize\/drag\/move the window<\/em> .请注意,FramelessWindowHint 不仅会移除标题栏和系统菜单以及窗口框架,还会移除您调整窗口大小\/拖动\/移动窗口的能力<\/em>。

My apologies for not taking out the StackOver1.pro.user file.我很抱歉没有取出 StackOver1.pro.user 文件。 Didn't think about it until just now.直到现在才考虑。 You will need to delete that or it could hose your build.您将需要删除它,否则它可能会影响您的构建。

"

You can do something like this你可以做这样的事情

self.setWindowTitle("‎") # Python

?

mainWindow.setWindowTitle(""); # C/C++

but instead of passing an empty string, pass an empty character.但不是传递一个空字符串,而是传递一个空字符。 This one worked for me: https://emptycharacter.com/这个对我有用: https ://emptycharacter.com/

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

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