pyqt工作列表徵圖問題

來源:互聯網
上載者:User

標籤:pyqt setwindowicon   pyqt工作列表徵圖   

今天在運行一個pyqt程式的時候發現setWindowIcon這個函數起了一半的作用,學Qt的都知道這個函數同時設定了程式的兩個地方的表徵圖顯示,

第一處在程式的左上方一個小表徵圖(只實用於window和linux,mac沒有的),第二處就是工作列的表徵圖,如:



在使用pyqt的時候你發現只有第一處設定成功了,而第二處則顯示的是pythonw.exe的表徵圖,

Google找了一下,解決了,下面就是詳細描述,英文稍差一點的同學就直接看解決方案吧,話說博主的英文也是爛的一塌糊塗

I‘ve found the answer, after some digging.

In Windows 7, the taskbar is not for "Application Windows" per se, it‘s for "Application User Models". For example, if you have several different instances of your application running, and each instance has its own icon, then they will all be grouped under a single taskbar icon. Windows uses various heuristics to decide whether different instances should be grouped or not, and in this case it decided that everything hosted by Pythonw.exe should be grouped under the icon for Pythonw.exe.

The correct solution is for Pythonw.exe to tell Windows that it is merely hosting other applications. Perhaps a future release of Python will do this. Alternatively, you can add a registry key to tell Windows that Pythonw.exe is just a host rather than an application in its own right. See MSDN documentation forAppUserModelIDs.

Alternatively, you can use a Windows call from Python, to explicitly tell Windows what the correct AppUserModelID is for this process:

簡而言之,我的理解就是pyqt是要給python解釋的,也就是說windows在啟動並執行時候認識到的是python,而你寫的程式則被看做是python這個主程式的一個子程式,這個時候你就要站出來告訴windows,我這個視窗強制使用單獨的AppUserModelID ,現在這個視窗擁有了一個新資源支配許可權,更多的可定製。

如果我的理解有誤,還請留言指正.

那到底要怎麼告訴windows呢:

import ctypesctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid")

以上只適用於windows,

但如果你不幸用的linux怎麼辦,其實更簡單,用過ubuntu的都知道每一個案頭軟體在/usr/share/applications目錄下面都對應一個表徵圖檔案 .desktop

等你軟體做好打包的時候自動添加這麼一個檔案就行了

當然用C++&Qt的同學就不會遇到這樣的問題了。

pyqt工作列表徵圖問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.