久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

無法在 Qt 樣式表中設置背景圖像

Unable to set the background image in Qt Stylesheet(無法在 Qt 樣式表中設置背景圖像)
本文介紹了無法在 Qt 樣式表中設置背景圖像的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在通過帶有參數樣式表的命令行運行我的 Qt 應用程序.控件的樣式有效,但在我嘗試為 MainWindow 加載背景圖像時無效.我試過了:

I'm running my Qt app through command line with a parameter -stylesheet. The styles for the controls work but not when I'm trying to load a background image for the MainWindow. I tried:

QMainWindow{
background-image:url(:image_256_8bit_latest_back.png);
}

還嘗試刪除背景中的:",但沒有任何區別.有人能告訴我這個樣式表有什么問題嗎?

Also tried removing the ":" in background, but doesn't make a difference. Can somebody tell me what's wrong with this StyleSheet?

推薦答案

您嘗試使用的圖像在哪里?

Where is located the image you are trying to use ?

您是否將其作為應用程序的資源?

Did you put it as a resource of your application ?

如果您想使用屬于資源一部分的圖像,您的項目中應該有一個資源文件 (*.qrc).該文件應包含如下內容:

If you want to use an image which is part of your resources, you should have a resource file (*.qrc) in your project. This file should contain something like this :

<RCC>
   <qresource prefix="/images">
      <file alias="sunset.jpg">sunset.jpg</file>
   </qresource>
</RCC>

然后,您可以在 QMainWindow 的構造函數中編寫此代碼:

Then, you could write this code in the constructor of your QMainWindow :

setStyleSheet("background-image: url(:/images/sunset.jpg);");

如果您不想使用 Qt 資源系統,您可以將圖像的路徑放在磁盤上:

If you don't want to use the Qt resource system, you can just put the path to your image on your disk :

setStyleSheet("background-image: url(res/images/sunset.jpg);");

但如果您使用相對路徑請小心:Qt 將從當前位置開始,這可能會改變,特別是如果您使用 Qt Creator 進行開發.

Be careful though if you are using a relative path : Qt will start from the current location, which might change, particularly if you are developping with Qt Creator.

使用 Qt Creator,當您在調試模式下運行應用程序時,當前路徑在 debug/ 中.當您在發布模式下運行您的應用時,當前路徑位于 release/(除非您更改了設置).

With Qt Creator, when you run your app in debug mode, the current path is in debug/. When you run your app in release mode, the current path is in release/ (unless you changed the settings).

這篇關于無法在 Qt 樣式表中設置背景圖像的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 91九色porny首页最多播放 | 色网在线观看 | 国产精品视频播放 | 精品美女 | 91亚洲精品在线 | 午夜欧美一区二区三区在线播放 | 亚洲欧美一区二区在线观看 | 日日摸日日碰夜夜爽2015电影 | 亚洲情综合五月天 | 国产精品入口麻豆www | 一区二区三区视频在线 | 五月婷六月丁香 | 欧美成人一区二区 | 日韩一区二区三区在线视频 | 亚洲一区二区电影在线观看 | 九九热这里 | 奇米久久久 | 亚洲免费在线播放 | 亚洲天堂一区 | 麻豆hd| aaa在线 | 一区二区三区国产好的精 | 国产亚洲一区二区精品 | aaa在线观看 | 翔田千里一区二区 | 久草综合在线 | 精品网站999 | 日本一二三区电影 | 99精品视频在线 | 热久久久久 | 国产最新网址 | 国产不卡在线观看 | 亚洲精品视频在线看 | 欧美在线视频一区二区 | 深夜爽视频 | 成人夜晚看av | 精品一区二区三 | 黄色毛片在线观看 | 视频一区二区在线观看 | 欧美综合在线观看 | 黄色一级大片在线免费看产 |