TAILIEUCHUNG - KDE 2/Qt Programming Bible phần 5

Tham khảo tài liệu 'kde 2/qt programming bible phần 5', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Chapter 12 Drawing and Painting with QPainter 277 13 14 DrawPixel DrawPixel QWidget parent const 15 char name QWidget parent name 16 17 setFixedSize 400 200 18 19 void DrawPixel paintEvent QPaintEvent 20 21 QPainter p this 22 QColor white 23 for int x 20 x 400 x 20 24 for int y 20 y 200 y 20 25 x-1 y 26 x 1 y 27 x y-1 28 x y 1 29 30 31 QColor red 32 for double x 0 x 400 x 33 double y sin x 30 34 y x 4 35 y 100 36 int x int y 37 38 The paintEvent method beginning on line 19 draws the grid points and the curve. Points by the way are drawn with the QPen normally used to draw lines. You can think of a pixel as the shortest of all possible lines. Line 22 calls setPen to establish a white pen for drawing the points and line 31 calls setPen to establish the red pen for drawing the dots making up the curve. The loop on lines 23 through 30 draws the collection of white points shown in Figure 12-9. The points are drawn at 20-pixel intervals both vertically and horizontally. Each point is drawn as four pixels one above and one to each side of the center point. The loop on lines 32 through 37 draws a sine wave that increases in amplitude from left to right. The variables x and y are declared as double to simplify the calculations. The window is fixed at 400 pixels wide so the value of x varies from 0 to 400 resulting in one painted pixel in each of the 400 pixel columns. Line 33 calculates the sine treating the value of x as a number of radians using a divisor other than 30 here will change the number of cycles that appear in the window . Line 34 multiplies the y value such that its magnitude becomes larger as x becomes larger. Line 35 adds 100 to the y value so it will be vertically centered in the window. The call to drawPoint on line 36 paints the pixel. 278 Part II Step by Step Drawing Arrays of Pixels In the previous example all of the points were calculated each time the window was painted. .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.