Qt paint brush and paint brush

Source: Internet
Author: User

#-*-Coding: UTF-8 -*-

# Python: 2.x

_ Author _ = 'admin'

# Paint brush and paint brush: qbrush defines the filling mode of qpainter and has attributes such as style, color, gradient, and texture.

# The style () of the paint brush defines the filling style, which is enumerated using QT: brushstyle. The default value is QT: nobrush, that is, no filling is performed.

# The color () of the paint brush defines the color of the fill mode. This color can be a color constant predefined by QT, that is

# QT: globalcolor, which can also be any qcolor object. Gradient () of the paint brush defines gradient filling. This attribute is only available when the style is QT: lineargradientpattern,

# QT: radialgradientpattern or QT: conicalgradientpattern. Gradient

# Qgradient object representation. Qt provides three gradient types: qlineargradient, qconicalgradient, and

# Qradialgradient, which are subclasses of qgradient. We can use the following code snippet to define

# Gradient painter

# Learning address: http://blog.csdn.net/lpp0900320123/article/details/25246873

From pyqt4.qtgui import *

From pyqt4.qt import *

From pyqt4 import qtgui, qtcore

From pyqt4.qtcore import *

Import sys

Class painterd (qwidget ):

Def _ init _ (Self ):

Super (painterd, self). _ init __()

Self. Resize (200,100)

Self. setwindowtitle ('paint ')

# Paint Brush

Def paintevent (self, e ):

Paint = qpainter (Self)

Paint. drawline (100,100,) # Straight Line

Pen = qpen (QT. Green, 5, QT. dashdotline, QT. flatcap, QT. roundjoin)

Paint. setpen (PEN) # use a paint brush

Rectanglen = qrectf (70 .., 40 .., 80 .., 60 .)

Start1 = 30*16

Start2 = 120*16

# Draw an arc

Paint. drawarc (rectanglen, start1, start2)

# Redefinition of paint brushes

Pen. setwidth (2)

Pen. setstyle (QT. solidline)

Paint. setpen (PEN)

Paint. drawrect (50, 50, 20,100)

Class painterd1 (qwidget ):

Def _ init _ (Self ):

Super (painterd1, self). _ init __()

Self. Resize (200,100)

Self. setwindowtitle ('paint ')

# Use painter

Def paintevent (self, qpaintevent ):

Paint = qpainter (Self)

Brush = qbrush (qcolor (255,), QT. dense4pattern) # create a brush

Paint. setbrush (Brush) # use a brush

Paint. drawellipse (, 50, 50) # elliptical

# Setting textures

Brush. settexture (qpixmap (r 'I/a.png '))

# Use four points to draw a polygon

Paint. drawpolygon (qpoint (150,100), qpoint (300,150), qpoint (350,250), qpoint (100,300 ))

Def main ():

APP = qtgui. qapplication (SYS. argv)

Ex = painterd1 ()

Ex. Show ()

Sys.exit(app.exe C _())

If _ name _ = '_ main __':

Main ()

:

Other friends do the example, you can learn: http://blog.csdn.net/cxm19830125/article/details/21733377

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.