在專案使用的,字串等資源檔案,在使用前首先新增到專案的資源檔案,在使用時使用如下命令進行新增:
this.imagelist1.imagestream = ((imageliststreamer)(resources.getobject("imagelist1.imagestream")));
以上命令新增了乙個imagelist資源。把資源從資源檔案獲取來,新增到程式介面。
this.imagelist1.images.setkeyname(0, "使用以上命令指定使用哪乙個檔案。close
");
同時也可以使用控制項自帶的新增的功能,右鍵點選該控制項,選擇新增新增。但是使用資源檔案的方式使得整個程式更加的統一,利於管理。而且可以再其他介面對資源檔案進行多次的重複使用。因此本人推薦使用資源檔案。
資源檔案的新增很簡單,開啟專案,雙擊property資料夾,就會彈出專案的屬性,選擇資源,就出現了專案包含的所有資源檔案。按照資源的型別進行新增。比如要新增,選擇資源型別為,然後找到要新增的,拖入該視窗即可。
this.imagelist1.imagestream = ((imageliststreamer)(resources.getobject("view codeimagelist1.imagestream
")));
this.imagelist1.transparentcolor =system.drawing.color.transparent;
this.imagelist1.images.setkeyname(0, "
close");
this.imagelist1.images.setkeyname(1, "
max"
);
this.imagelist1.images.setkeyname(2, "
min"
);
this.imagelist1.images.setkeyname(3, "
normal");
this.imagelist1.images.setkeyname(4, "
cameradisconn");
this.imagelist1.images.setkeyname(5, "
cameraconn");
this.imagelist1.images.setkeyname(6, "
cameraseach");
this.imagelist1.images.setkeyname(7, "
iosearch");
this.imagelist1.images.setkeyname(8, "
iocon.bmp");
this.imagelist1.images.setkeyname(9, "
iodiscon.bmp");
this.imagelist1.images.setkeyname(10, "
search.bmp");
this.imagelist1.images.setkeyname(11, "
right.bmp");
this.imagelist1.images.setkeyname(12, "
err.bmp");
this.imagelist1.images.setkeyname(13, "
waiting.bmp
");
以上是兩種方式使用資源,8之前使用的是專案的資源檔案,8以後使用的是控制項自帶的新增的方法使用資源。
資源檔案的使用
學習pyqt推薦大家看這本書 第一步 new file qt resource file 第二步 add prefix建乙個字首 prefix 相當於建立乙個資料夾嘛,可以分類圖示。新增具體圖示就是add files就可以了。這裡的images這個子資料夾,你在命名的加上 images就可以了。su...
qt cmake 新增資源檔案的問題
1 新增專案 file glob recurse qrc source files qrc cmake current source dir是和cmakelist的路徑 2 新增資源檔案 set qrc source files image.qrc qt5 add resources qrc fil...
如何使用資源檔案
昨天突發奇想,向寫乙個類似於msn 的自定義個性化窗體,今天在實踐的過程中,發現在實現資源檔案時就遇到了困難。在網上找了不少的資料,將怎麼新增資源檔案的很多,比如這個 就不錯,而且其中也註解了 注意 resourcemanager rm new resourcemanager res.my asse...