Qt Gui Intro

Embed Size (px)

Citation preview

  • 8/18/2019 Qt Gui Intro

    1/53

  • 8/18/2019 Qt Gui Intro

    2/53

  • 8/18/2019 Qt Gui Intro

    3/53

  • 8/18/2019 Qt Gui Intro

    4/53

  • 8/18/2019 Qt Gui Intro

    5/53

  • 8/18/2019 Qt Gui Intro

    6/53

  • 8/18/2019 Qt Gui Intro

    7/53

  • 8/18/2019 Qt Gui Intro

    8/53

  • 8/18/2019 Qt Gui Intro

    9/53

  • 8/18/2019 Qt Gui Intro

    10/53

  • 8/18/2019 Qt Gui Intro

    11/53

  • 8/18/2019 Qt Gui Intro

    12/53

  • 8/18/2019 Qt Gui Intro

    13/53

  • 8/18/2019 Qt Gui Intro

    14/53

  • 8/18/2019 Qt Gui Intro

    15/53

  • 8/18/2019 Qt Gui Intro

    16/53

  • 8/18/2019 Qt Gui Intro

    17/53

  • 8/18/2019 Qt Gui Intro

    18/53

  • 8/18/2019 Qt Gui Intro

    19/53

  • 8/18/2019 Qt Gui Intro

    20/53

  • 8/18/2019 Qt Gui Intro

    21/53

  • 8/18/2019 Qt Gui Intro

    22/53

  • 8/18/2019 Qt Gui Intro

    23/53

  • 8/18/2019 Qt Gui Intro

    24/53

  • 8/18/2019 Qt Gui Intro

    25/53

  • 8/18/2019 Qt Gui Intro

    26/53

  • 8/18/2019 Qt Gui Intro

    27/53

  • 8/18/2019 Qt Gui Intro

    28/53

  • 8/18/2019 Qt Gui Intro

    29/53

  • 8/18/2019 Qt Gui Intro

    30/53

  • 8/18/2019 Qt Gui Intro

    31/53

  • 8/18/2019 Qt Gui Intro

    32/53

  • 8/18/2019 Qt Gui Intro

    33/53

  • 8/18/2019 Qt Gui Intro

    34/53

  • 8/18/2019 Qt Gui Intro

    35/53

  • 8/18/2019 Qt Gui Intro

    36/53

  • 8/18/2019 Qt Gui Intro

    37/53

    %idgets

  • 8/18/2019 Qt Gui Intro

    38/53

    Common wid,ets

  • 8/18/2019 Qt Gui Intro

    39/53

    Wid,et 'i,nals

    QPush/utton clicked9:

    Q$ine@dit editing)inished9:* returnPressed9:* te=tChanged9const QFtringN:

    QCombo/o= activated9int:* current>nde=Changed9int:QCheck/o= stateChanged9int:

    QFpin/o= valueChanged9int:

    QFlider rangeChanged9int*int:* valueChanged9int:

    Common si,nals

    http://pyqt.sourceforge.net/Docs/PyQt4/qpushbutton.htmlhttp://pyqt.sourceforge.net/Docs/PyQt4/qlineedit.htmlhttp://pyqt.sourceforge.net/Docs/PyQt4/qcombobox.htmlhttp://pyqt.sourceforge.net/Docs/PyQt4/qcheckbox.htmlhttp://pyqt.sourceforge.net/Docs/PyQt4/qspinbox.htmlhttp://pyqt.sourceforge.net/Docs/PyQt4/qslider.htmlhttp://pyqt.sourceforge.net/Docs/PyQt4/qslider.htmlhttp://pyqt.sourceforge.net/Docs/PyQt4/qspinbox.htmlhttp://pyqt.sourceforge.net/Docs/PyQt4/qcheckbox.htmlhttp://pyqt.sourceforge.net/Docs/PyQt4/qcombobox.htmlhttp://pyqt.sourceforge.net/Docs/PyQt4/qlineedit.htmlhttp://pyqt.sourceforge.net/Docs/PyQt4/qpushbutton.html

  • 8/18/2019 Qt Gui Intro

    40/53

    !ialogs

  • 8/18/2019 Qt Gui Intro

    41/53

    Q?ialo,● /ase class of dialog window widgets● 8eneral !ialogs can have 5 modes<

    ● -odal dialo,● Remains in foreground* until closed● /locks input to remaining application● @=ample< Configuration dialog

    ● (on%-odal dialo,● Eperates independently in application● @=ample< )ind Fearch dialog

  • 8/18/2019 Qt Gui Intro

    42/53

    /uilding ser >nterfaces

  • 8/18/2019 Qt Gui Intro

    43/53

    Qt ?esi,ner

  • 8/18/2019 Qt Gui Intro

    44/53

    "uild .& usin, Qt?esi,ner 1/8● Qt !esigner uses @- Aui files to store designs and does not generate any code itself

    ● pyuic4 takes a Qt3 user interface description file and compiles it to Python code

    ● he Python code is structured as a single class that is derived from the Python obAect type

    ● Class name is the name of the top level obAect set in !esigner with Ui_ prepended

    ● he class contains a method called setupUi()● his takes a single argument which is the widget in which the user interface is created

  • 8/18/2019 Qt Gui Intro

    45/53

    "uild .& usin, Qt?esi,ner 2/81: create your 8 > 9or use #y!ialog(ui from pyuic@=ample:

    5: generate the (py file

    pyuic4 -o MyDialog_auto.py MyDialog.ui

    ,: use ui interface

    from MyDialog_auto import Ui_Dialog

    app = QApplication(sys.argv)

    Dialog = QDialog() ### create new dialogui = Ui_Dialog() ### create a new instance of your guiui.setupUi(Dialog) ### apply the gui to the created dialog

    Dialog.show()sys.exit(app.exec_())

  • 8/18/2019 Qt Gui Intro

    46/53

  • 8/18/2019 Qt Gui Intro

    47/53

    -atplotlib and Qt 1/;-atplotlib is a Python 5! interactive plotting library

    http< matplotlib(org

    %e will see how to<

    l @mbed a #atplotlib )igure into a Qt windowl @mbed a 'avigation oolbar

    http://matplotlib.org/http://matplotlib.org/

  • 8/18/2019 Qt Gui Intro

    48/53

    -atplotlib and Qt 2/;Epen MatplotlibExample/matplotlibExample.py

    ;pp features<●

    generate a set of 5 points and plot it pressingBPlot button

    ● show navigation toolbar for Gooming panning

  • 8/18/2019 Qt Gui Intro

    49/53

    -atplotlib and Qt 8/;#import modules from Matplotlibfrom matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvasfrom matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbarimport matplotlib.pyplot as plt

    #import random module to generate setimport random

    Bi,ure #atplotlib obAect< this is the backend-independent representation of our plot

    >mport from the matplotlibAbackendsAbackend Dt9a,, the module Bi,ureCan3asQ)!,, class* which isthe backend-dependent figure canvas( >t contains the backend-specific knowledge to render the)igure weDve drawn(

    'ote that Bi,ureCan3asQ)!,, * other than being a #atplotlib class* is also a Qwidget*the base class of all user interface obAects( Fo this means we can treat )igureCanvasQ ;gg likea pure Qt widget EbAect( 'avigation oolbar5Q ;gg also inherits from Q%idget* so it can be used asQt obAects in a Qapplication(

    References<http< matplotlib(org api backendO4t3aggOapi(html

    http< matplotlib(org api pyplotOapi(htmlhttp< matplotlib(org api figureOapi(html module-matplotlib(figure

    https< docs(python(org 5 library random(html

    http://matplotlib.org/api/backend_qt4agg_api.htmlhttp://matplotlib.org/api/pyplot_api.htmlhttp://matplotlib.org/api/figure_api.html#module-matplotlib.figurehttps://docs.python.org/2/library/random.htmlhttps://docs.python.org/2/library/random.htmlhttp://matplotlib.org/api/figure_api.html#module-matplotlib.figurehttp://matplotlib.org/api/pyplot_api.htmlhttp://matplotlib.org/api/backend_qt4agg_api.html

  • 8/18/2019 Qt Gui Intro

    50/53

    -atplotlib and Qt 9/;

    class Window(QtGui.QDialog): def __init__(self, parent=None): super(Window, self).__init__(parent)

    #init figure and canvas self.figure = plt.figure() self.canvas = FigureCanvas(self.figure)

    #init nav toolbar self.toolbar = NavigationToolbar(self.canvas, self)

    # Add plot button self.button = QtGui.QPushButton('Plot')

    # connect button to custom slot (see later)

    self.button.clicked.connect( self.plot )

    # set the layout layout = QtGui.QVBoxLayout() layout.addWidget(self.toolbar) layout.addWidget(self.canvas) layout.addWidget(self.button) self.setLayout(layout)

  • 8/18/2019 Qt Gui Intro

    51/53

    -atplotlib and Qt :/;

    ### our custom slotdef plot (self): # random data data = [random.random() for i in range(25)]

    # create an axis ax = self.figure.add_subplot(1,1,1)

    # discards the old graph ax.hold(False)

    # plot data ax.plot(data, '*-')

    # refresh canvas self.canvas.draw()

  • 8/18/2019 Qt Gui Intro

    52/53

    -atplotlib and Qt ;/;

    @=ercise

    #odify the previous e=ample adding custombuttons which will act as the navigation toolbar<

    Plot plot random dataset

    oom activate Goom on canvasPan activate pan on canvasKome reset view

    Kint 1< you will have to connect your buttons to navigationtoolbar zoom() , pan() and home() methods

    Hint #2: open MatplotlibExample/matplotlibExampleCustom.py

  • 8/18/2019 Qt Gui Intro

    53/53

    Eesources[P ! Py#t white$a$er http< www(riverbankcomputing(co(uk static !ocs PyQt3 py4t-whitepaper-a3(pdf

    [%&&' Ra$id ()* Programming with Python and #t http< 4t-proAect(org books view rapidOguiOprogrammingOwithOpythonOandO4t

    http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/pyqt-whitepaper-a4.pdfhttp://qt-project.org/books/view/rapid_gui_programming_with_python_and_qthttp://qt-project.org/books/view/rapid_gui_programming_with_python_and_qthttp://www.riverbankcomputing.co.uk/static/Docs/PyQt4/pyqt-whitepaper-a4.pdf