<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Qyoto 中的繪圖 > 原文: [http://zetcode.com/gui/vbqyoto/painting/](http://zetcode.com/gui/vbqyoto/painting/) 在 Visual Basic Qyoto 編程教程的這一部分中,我們將進行繪圖。 我們什么時候需要油漆? 在某些情況下,當我們需要從頭開始創建小部件時。 在這種情況下,我們需要繪圖。 或者我們想創建圖表,特殊裝飾,效果或小部件增強。 當我們在 Qyoto 庫中進行繪圖時,`QPainter`類非常有用。 繪圖事件通過`PaintEvent()`方法接收。 若要進行自定義繪圖,我們必須重新實現此方法。 ## 圖案 在《京都議定書》中,我們可以使用各種圖案來填充形狀的內部。 ```vb ' ZetCode Mono Visual Basic Qt tutorial ' ' This program draws nine rectangles. ' The interiors are filled with ' different built-in patterns. ' ' author jan bodnar ' last modified May 2009 ' website www.zetcode.com Imports Qyoto Public Class VBQApp Inherits QWidget Public Sub New() Me.SetWindowTitle("Patterns") Me.Resize(350, 280) Me.Move(300, 300) Me.Show() End Sub Protected Overrides Sub PaintEvent(ByVal e As QPaintEvent) Dim painter As New QPainter(Me) Me.DrawPatterns(painter) painter.End() End Sub Private Sub DrawPatterns(ByRef painter As QPainter) painter.SetPen(PenStyle.NoPen) painter.SetBrush(Qt.BrushStyle.HorPattern) painter.DrawRect(10, 15, 90, 60) painter.SetBrush(Qt.BrushStyle.VerPattern) painter.DrawRect(130, 15, 90, 60) painter.SetBrush(Qt.BrushStyle.CrossPattern) painter.DrawRect(250, 15, 90, 60) painter.SetBrush(Qt.BrushStyle.Dense7Pattern) painter.DrawRect(10, 105, 90, 60) painter.SetBrush(Qt.BrushStyle.Dense6Pattern) painter.DrawRect(130, 105, 90, 60) painter.SetBrush(Qt.BrushStyle.Dense5Pattern) painter.DrawRect(250, 105, 90, 60) painter.SetBrush(Qt.BrushStyle.BDiagPattern) painter.DrawRect(10, 195, 90, 60) painter.SetBrush(Qt.BrushStyle.FDiagPattern) painter.DrawRect(130, 195, 90, 60) painter.SetBrush(Qt.BrushStyle.DiagCrossPattern) painter.DrawRect(250, 195, 90, 60) End Sub Public Shared Sub Main(ByVal args() As String) Dim qapp As New QApplication(args) Dim app As New VBQApp QApplication.Exec() End Sub End Class ``` 在代碼示例中,我們將繪制九個矩形,并用不同的畫筆圖案填充它們。 ```vb Protected Overrides Sub PaintEvent(ByVal e As QPaintEvent) Dim painter As New QPainter(Me) Me.DrawPatterns(painter) painter.End() End Sub ``` 當需要重繪窗口區域時,將調用`PaintEvent()`方法。 當我們調整窗口大小,最大化或最小化窗口時,就會發生這種情況。在此方法中,我們創建了`QPainter`對象。 該對象用于完成 Qyoto 中的所有繪圖。 繪圖本身被委托給`DrawPatterns()`方法。 `End()`方法釋放繪圖時使用的資源。 ```vb painter.SetPen(PenStyle.NoPen) ``` 筆對象用于繪制形狀的輪廓。 在我們的示例中,我們將不使用筆。 ```vb painter.SetBrush(Qt.BrushStyle.HorPattern) ``` 我們將水平圖案設置為畫筆。 畫筆用于繪制形狀的內部。 ```vb painter.DrawRect(10, 15, 90, 60) ``` 我們使用當前的筆和畫筆繪制一個矩形。 該方法的前兩個參數是 x,y 坐標。 最后兩個參數是矩形的寬度和高度。 ![Patterns](https://img.kancloud.cn/9a/a0/9aa03f30abece400abcdc7bede5e85f2_356x305.jpg) 圖:圖案 ## 形狀 Qyoto 繪圖 API 可以繪制各種形狀。 以下編程代碼示例將顯示其中的一些。 ```vb ' ZetCode Mono Visual Basic Qt tutorial ' ' This program draws basic shapes ' available in Qyoto. ' ' author jan bodnar ' last modified May 2009 ' website www.zetcode.com Imports Qyoto Public Class VBQApp Inherits QWidget Public Sub New() Me.SetWindowTitle("Shapes") Me.Resize(350, 280) Me.Move(300, 300) Me.Show() End Sub Protected Overrides Sub PaintEvent(ByVal e As QPaintEvent) Dim painter As New QPainter(Me) Me.DrawShapes(painter) painter.End() End Sub Private Sub DrawShapes(ByRef painter As QPainter) painter.SetRenderHint(QPainter.RenderHint.Antialiasing) painter.SetPen(New QPen(New QBrush(New QColor("Gray")), 1)) painter.SetBrush(New QBrush(New QColor("Gray"))) Dim path1 As New QPainterPath() path1.MoveTo(5, 5) path1.CubicTo(40, 5, 50, 50, 99, 99) path1.CubicTo(5, 99, 50, 50, 5, 5) painter.DrawPath(path1) painter.DrawPie(130, 20, 90, 60, 30*16, 120*16) painter.DrawChord(240, 30, 90, 60, 0, 16*180) painter.DrawRoundRect(20, 120, 80, 50) Dim polygon As New QPolygon(5) polygon.SetPoint(0, 130, 140) polygon.SetPoint(1, 180, 170) polygon.SetPoint(2, 180, 140) polygon.SetPoint(3, 220, 110) polygon.SetPoint(4, 140, 100) painter.DrawPolygon(polygon) painter.DrawRect(250, 110, 60, 60) Dim baseline As New QPointF(20, 250) Dim font As New QFont("Georgia", 55) Dim path2 As New QPainterPath() path2.AddText(baseline, font, "Q") painter.DrawPath(path2) painter.DrawEllipse(140, 200, 60, 60) painter.DrawEllipse(240, 200, 90, 60) End Sub Public Shared Sub Main(ByVal args() As String) Dim qapp As New QApplication(args) Dim app As New VBQApp QApplication.Exec() End Sub End Class ``` 在此代碼示例中,我們在窗口上繪制了九種不同的形狀。 復雜路徑,餅圖,和弦,圓角矩形,多邊形,矩形,基于字符的形狀,圓形和橢圓形。 ```vb painter.SetRenderHint(QPainter.RenderHint.Antialiasing) ``` 我們在示例中使用抗鋸齒。 抗鋸齒形狀看起來更好,但是繪制它們需要更多時間。 ```vb painter.SetPen(New QPen(New QBrush(New QColor("Gray")), 1)) painter.SetBrush(New QBrush(New QColor("Gray"))) ``` 我們使用深灰色的筆和畫筆繪制形狀。 ```vb Dim path1 As New QPainterPath() path1.MoveTo(5, 5) path1.CubicTo(40, 5, 50, 50, 99, 99) path1.CubicTo(5, 99, 50, 50, 5, 5) painter.DrawPath(path1) ``` 使用`QPainterPath`對象創建第一個復雜形狀。 `QPainterPath`類為繪圖操作提供了一個容器。 畫家路徑是由許多圖形構造塊(例如矩形,橢圓形,直線和曲線)組成的對象。 ```vb painter.DrawPie(130, 20, 90, 60, 30*16, 120*16) painter.DrawChord(240, 30, 90, 60, 0, 16*180) painter.DrawRoundRect(20, 120, 80, 50) ``` 這三行畫出一個餅圖,一個和弦和一個圓角矩形。 ```vb Dim polygon As New QPolygon(5) polygon.SetPoint(0, 130, 140) polygon.SetPoint(1, 180, 170) polygon.SetPoint(2, 180, 140) polygon.SetPoint(3, 220, 110) polygon.SetPoint(4, 140, 100) painter.DrawPolygon(polygon) ``` 在這里,我們創建一個多邊形。 ```vb Dim baseline As New QPointF(20, 250) Dim font As New QFont("Georgia", 55) Dim path2 As New QPainterPath() path2.AddText(baseline, font, "Q") painter.DrawPath(path2) ``` 這些線創建基于字符的形狀。 ```vb painter.DrawEllipse(140, 200, 60, 60) painter.DrawEllipse(240, 200, 90, 60) ``` 這兩條線分別創建一個圓和一個橢圓。 ![Shapes](https://img.kancloud.cn/47/8e/478eee4c52e3235b6b017ebb5a02264b_356x305.jpg) 圖:形狀 ## 透明矩形 透明性是指能夠透視材料的質量。 了解透明度的最簡單方法是想象一塊玻璃或水。 從技術上講,光線可以穿過玻璃,這樣我們就可以看到玻璃后面的物體。 在計算機圖形學中,我們可以使用 alpha 合成來實現透明效果。 Alpha 合成是將圖像與背景組合以創建部分透明外觀的過程。 合成過程使用 Alpha 通道。 (wikipedia.org,answers.com) ```vb ' ZetCode Mono Visual Basic Qt tutorial ' ' This program draws ten ' rectangles with different ' levels of transparency ' ' author jan bodnar ' last modified May 2009 ' website www.zetcode.com Imports Qyoto Public Class VBQApp Inherits QWidget Public Sub New() Me.SetWindowTitle("Transparent rectangles") Me.Resize(590, 90) Me.Move(300, 300) Me.Show() End Sub Protected Overrides Sub PaintEvent(ByVal e As QPaintEvent) Dim painter As New QPainter(Me) Me.DrawRectangles(painter) painter.End() End Sub Private Sub DrawRectangles(ByRef painter As QPainter) painter.SetPen(PenStyle.NoPen) For i As Integer = 1 To 10 painter.SetBrush(New QBrush(New QColor(0, 0, 255, i*25))) painter.DrawRect(50*i, 20, 40, 40) Next End Sub Public Shared Sub Main(ByVal args() As String) Dim qapp As New QApplication(args) Dim app As New VBQApp QApplication.Exec() End Sub End Class ``` 在示例中,我們將繪制十個具有不同透明度級別的矩形。 ```vb painter.SetPen(PenStyle.NoPen) ``` 我們不用筆。 ```vb For i As Integer = 1 To 10 painter.SetBrush(New QBrush(New QColor(0, 0, 255, i*25))) painter.DrawRect(50*i, 20, 40, 40) Next ``` `QColor`對象的最后一個參數是 alpha 透明度值。 ![Transparent rectangles](https://img.kancloud.cn/06/28/062818c5414b78ef1b9b1b6cda348f85_596x115.jpg) 圖:透明矩形 ## 甜甜圈形狀 在下面的示例中,我們通過旋轉一堆橢圓來創建復雜的形狀。 ```vb ' ZetCode Mono Visual Basic Qt tutorial ' ' This program draws a donut ' shape ' ' author jan bodnar ' last modified May 2009 ' website www.zetcode.com Imports Qyoto Public Class VBQApp Inherits QWidget Public Sub New() Me.SetWindowTitle("Donut") Me.Resize(350, 280) Me.Move(300, 300) Me.Show() End Sub Protected Overrides Sub PaintEvent(ByVal e As QPaintEvent) Dim painter As New QPainter(Me) Me.DrawDonut(painter) painter.End() End Sub Private Sub DrawDonut(ByRef painter As QPainter) Dim color As New QColor() color.SetNamedColor("#333333") Dim pen As New QPen(color) pen.setWidthF(0.5) painter.SetPen(pen) painter.SetRenderHint(QPainter.RenderHint.Antialiasing) Dim h As Integer = Me.Height() Dim w As Integer = Me.Width() painter.Translate(New QPoint(w/2, h/2)) For rot As Integer = 1 To 360 Step 5 painter.DrawEllipse(-125, -40, 250, 80) painter.Rotate(5) Next End Sub Public Shared Sub Main(ByVal args() As String) Dim qapp As New QApplication(args) Dim app As New VBQApp QApplication.Exec() End Sub End Class ``` 在此示例中,我們創建一個甜甜圈。 形狀類似于曲奇,因此得名“甜甜圈”。 ```vb Dim color As New QColor() color.SetNamedColor("#333333") ``` 我們可以使用十六進制表示法來創建顏色對象。 ```vb Dim h As Integer = Me.Height() Dim w As Integer = Me.Width() ``` 在這里,我們確定窗口的寬度和高度。 ```vb painter.Translate(New QPoint(w/2, h/2)) ``` 我們將坐標系移到窗口的中間。 這樣,我們使繪圖在數學上更容易。 ```vb For rot As Integer = 1 To 360 Step 5 painter.DrawEllipse(-125, -40, 250, 80) painter.Rotate(5) Next ``` 我們繪制一個橢圓對象 72 次。 每次,我們將橢圓旋轉 5 度。 這將創建我們的甜甜圈形狀。 ![Donut](https://img.kancloud.cn/42/4e/424e9b56c7a6cc6373c5f03e71b8aa83_356x305.jpg) 圖:多納圈 ## 繪制文字 在最后一個示例中,我們將在窗口上繪制文本。 ```vb ' ZetCode Mono Visual Basic Qt tutorial ' ' This program draws text ' on the window ' ' author jan bodnar ' last modified May 2009 ' website www.zetcode.com Imports Qyoto Public Class VBQApp Inherits QWidget Public Sub New() Me.SetWindowTitle("Unfaitful") Me.Resize(300, 280) Me.Move(300, 300) Me.Show() End Sub Protected Overrides Sub PaintEvent(ByVal e As QPaintEvent) Dim painter As New QPainter(Me) Me.DrawLyrics(painter) painter.End() End Sub Private Sub DrawLyrics(ByRef painter As QPainter) painter.SetBrush(New QBrush(new QColor(25, 25, 25))) painter.SetFont(New QFont("Purisa", 10)) painter.DrawText(New QPoint(20, 30), _ "I don't wanna do this anymore") painter.DrawText(New QPoint(20, 60), _ "I don't wanna be the reason why") painter.DrawText(New QPoint(20, 90), _ "Everytime I walk out the door") painter.DrawText(New QPoint(20, 120), _ "I see him die a little more inside") painter.DrawText(New QPoint(20, 150), _ "I don't wanna hurt him anymore") painter.DrawText(New QPoint(20, 180), _ "I don't wanna take away his life") painter.DrawText(New QPoint(20, 210), _ "I don't wanna be...") painter.DrawText(New QPoint(20, 240), _ "A murderer") End Sub Public Shared Sub Main(ByVal args() As String) Dim qapp As New QApplication(args) Dim app As New VBQApp QApplication.Exec() End Sub End Class ``` 我們在窗口上畫一首歌歌詞。 ```vb painter.SetFont(New QFont("Purisa", 10)) ``` 我們為文本設置了 Purisa 字體。 ```vb painter.DrawText(New QPoint(20, 30), _ "I don't wanna do this anymore") ``` `DrawText()`方法用于繪制文本。 ![Drawing text](https://img.kancloud.cn/31/42/314270fefc07a0f0ae5b5ab148fd5a47_376x265.jpg) 圖:繪制文本 在 Visual Basic Qyoto 編程教程的這一部分中,我們做了一些繪圖。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看