Using ERIC6 and PYQT5 to achieve Python's extreme GUI Programming (series)----Drawing (Drawing) (3)--Draw line

Source: Internet
Author: User

Overview

This article implements the following program: ( draw a variety of different styles of lines in the form )

The main steps are as follows:

1. Create a new project in Eric6, create a new form

2, (automatically open) into PyQt5 Desinger, edit the GUI, save

3, back to Eric 6, to the previous step to get the interface file Drawing.ui file right-click, compile the form, get ui_drawing.py file

4, then right-click on the Drawing.ui file, generate dialog code, get drawing.py file. ( add your own program logic in drawing.py )

5, Py2exe package into EXE file (this step)

Body

Next to "Overview" Step 4th:

In drawing.py, the paint event is defined first:

    def paintevent (Self, event):         = Qtgui.qpainter ()        qp.begin (self)        # Custom Draw line method        qp.end ()

Then, customize the line drawing method:

    defdrawlines (Self, QP): Pen= Qtgui.qpen (QtCore.Qt.black, 2, QtCore.Qt.SolidLine) qp.setpen (pen) qp.drawline (20, 40, 250, 40) Pen.setstyle (QtCore.Qt.DashLine) qp.setpen (pen) qp.drawline (20, 80, 250, 80) Pen.setstyle (QtCore.Qt.DashDotLine) qp.setpen (pen) qp.drawline (20, 120, 250, 120) Pen.setstyle (QtCore.Qt.DotLine) qp.setpen (pen) qp.drawline (20, 160, 250, 160) Pen.setstyle (QtCore.Qt.DashDotDotLine) qp.setpen (pen) qp.drawline (20, 200, 250, 200) Pen.setstyle (QtCore.Qt.CustomDashLine) Pen.setdashpattern ([1, 4, 5, 4]) Qp.setpen (pen) qp.drawline (20, 240, 250, 240)

Together, drawing.py is like this:

#-*-coding:utf-8-*-"""Module implementing Drawing."""ImportSYS fromPyQt5ImportQtgui, Qtcore fromPyqt5.qtwidgetsImportQdialog, Qapplication fromUi_drawingImportui_drawingclassDrawing (Qdialog, ui_drawing):def __init__(Self, parent=None): Super (Drawing, self).__init__(parent) self.setupui (self)defpaintevent (Self, event): QP=Qtgui.qpainter () qp.begin (self) self.drawlines (QP) qp.end ()defdrawlines (Self, QP): Pen= Qtgui.qpen (QtCore.Qt.black, 2, QtCore.Qt.SolidLine) qp.setpen (pen) qp.drawline (20, 40, 250, 40) Pen.setstyle (QtCore.Qt.DashLine) qp.setpen (pen) qp.drawline (20, 80, 250, 80) Pen.setstyle (QtCore.Qt.DashDotLine) qp.setpen (pen) qp.drawline (20, 120, 250, 120) Pen.setstyle (QtCore.Qt.DotLine) qp.setpen (pen) qp.drawline (20, 160, 250, 160) Pen.setstyle (QtCore.Qt.DashDotDotLine) qp.setpen (pen) qp.drawline (20, 200, 250, 200) Pen.setstyle (QtCore.Qt.CustomDashLine) Pen.setdashpattern ([1, 4, 5, 4]) Qp.setpen (pen) qp.drawline (20, 240, 250, 240)if __name__=='__main__': App=qapplication (SYS.ARGV) dlg=Drawing () dlg.show () Sys.exit (App.exec_ ())

Using ERIC6 and PYQT5 to achieve Python's extreme GUI Programming (series)----Drawing (Drawing) (3)--Draw line

Related Article

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.