tailieunhanh - KDE 2/Qt Programming Bible phần 4

Các nút được tạo ra và được thêm vào trên đường dây 30 thông qua 33 mất vị trí trực tiếp trên đầu trang của các nút khác được đóng gói từ phía dưới, và một trên đường 35 qua 38 chiếm một vị trí trực tiếp trên hai ở phía dưới. | Chapter 9 Graphics File Formats 203 This example creates a small pixmap from the XPM data included in the source on line 6. The actual size of the pixmap is ignored and it is set as the background pixmap on line 13 the size of the widget is set on line 14. The result is the window shown in Figure 9-2. Figure 9-2 Displaying compiled XPM data as a tiled background Loading a Pixmap from a File You can load a graphic from a file instead of compiling it as part of the program by making a slight change to the previous example. All that is needed is a different method to create the pixmap. The following program loads and displays the logo pixmap previously shown in Figure 9-1 1 2 include 3 include 4 include 5 6 int main int argc char argv 7 8 KApplication app argc argv showfilexpm 9 QPixmap 10 QWidget widget new QWidget 11 widget- setFixedSize 12 widget- setBackgroundPixmap pixmap 13 widget- show 14 widget 15 return 16 The QPixmap constructor on line 9 uses a file to locate the graphic data. You can use file types other than XPM. For example to load a different type of file change the filename on line 9 as follows QPixmap The software does not look at the suffix of the filename to determine the file type. Instead it loads a block of data from the beginning of the file and inspects it to determine the file type. This is why the commented string containing the characters XPM must remain at the top of an XPM file. 204 Part II Step by Step If the software complains about an invalid XPM file it may be in an older format. The file must be in version 3 in order for you to use it. Make the conversion with a command like the following sxpm -nod -o In order to load from a graphic file the software must understand the file format. The Qt software supports the file types PNG BMP GIF JPEG XBM XPM and PNM. The Qt software was designed

TỪ KHÓA LIÊN QUAN