简体   繁体   English

如何在Qt QWidget中更改tittleBar按钮(如关闭和最小化按钮)

[英]how can change tittleBar button like close and minimize button in Qt QWidget

i want to change style of QWidget tittleBar button like close and minimize in windows but there is no similar stylesheet elements. 我想更改QWidget tittleBar按钮的样式,例如在窗口中关闭并最小化,但是没有类似的样式表元素。 i am using Qt5.1 and windows7. 我正在使用Qt5.1和Windows7。

can any body help me? 有谁能够帮助我?

If you are talking about how to do this windows, you can do: 如果您正在谈论如何执行此窗口,则可以执行以下操作:

this->setWindowIcon(QIcon(":myiconfile.png"));

You will have to add the file in your resources. 您将必须在资源中添加文件。

You can set the window icon on your widget as per documentation with the following property: 您可以根据文档使用以下属性在窗口小部件上设置窗口图标:

windowIcon : QIcon windowIcon:QIcon

This property holds the widget's icon. 此属性保存小部件的图标。

This property only makes sense for windows. 此属性仅对Windows有意义。 If no icon has been set, windowIcon() returns the application icon (QApplication::windowIcon()). 如果未设置任何图标,则windowIcon()返回应用程序图标(QApplication :: windowIcon())。

So, your code would look like something like this: 因此,您的代码看起来像这样:

myWidget->setWindowIcon("/path/to/your/icon/file"); myWidget-> setWindowIcon( “/路径/到/你/图标/文件”);

The icon file path can be relative and absolute as well as one coming from the resource system. 图标文件路径可以是相对路径,也可以是绝对路径,也可以是来自资源系统的路径。 The easiest way to test it quickly is just to use the absolute path, but if you plan to ship assets with your application to be self-contained, then you can use resource file with the resource system . 快速测试它的最简单方法就是使用绝对路径,但是如果您打算将资产与应用程序一起交付时是独立的,则可以将资源文件与资源系统一起使用

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

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