Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Displaying numbers with QLCDNumber.display() with PyQt5
Forum Updated to NodeBB v4.3 + New Features

Displaying numbers with QLCDNumber.display() with PyQt5

Scheduled Pinned Locked Moved Solved Language Bindings
10 Posts 2 Posters 7.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maett1990
    wrote on 25 Aug 2018, 08:52 last edited by
    #1

    I am bit new to Qt and python. I have created a simple GUI which consist of a simple calculator. I used the QT Designer to design the GUI and now I want to link my buttons to the QLCDNumber display.

    I created a *.clicked.connect(self.my_func) to link it but only the print statement is working well when clicking the button.

    from PyQt5 import QtCore, QtGui, QtWidgets

    class Ui_Dialog(object):
    def setupUi(self, Dialog):
    Dialog.setObjectName("Dialog")
    self.gridLayoutWidget = QtWidgets.QWidget(Dialog)
    self.gridLayoutWidget.setGeometry(QtCore.QRect(20, 80, 164, 134))
    self.gridLayoutWidget.setObjectName("gridLayoutWidget")
    self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
    self.gridLayout.setContentsMargins(0, 0, 0, 0)
    self.gridLayout.setObjectName("gridLayout")

        self.pushButton_9 = QtWidgets.QPushButton(self.gridLayoutWidget)
        self.pushButton_9.setObjectName("pushButton_9")
        self.gridLayout.addWidget(self.pushButton_9, 0, 2, 1, 1)
        self.pushButton_9.clicked.connect(self.my_func)
    
        self.pushButton_5 = QtWidgets.QPushButton(self.gridLayoutWidget)
        self.pushButton_5.setObjectName("pushButton_5")
        self.gridLayout.addWidget(self.pushButton_5, 1, 1, 1, 1)
        self.pushButton_7 = QtWidgets.QPushButton(self.gridLayoutWidget)
        self.pushButton_7.setObjectName("pushButton_7")
        self.gridLayout.addWidget(self.pushButton_7, 0, 0, 1, 1)
        self.pushButton_6 = QtWidgets.QPushButton(self.gridLayoutWidget)
        self.pushButton_6.setObjectName("pushButton_6")
        self.gridLayout.addWidget(self.pushButton_6, 1, 2, 1, 1)
        self.pushButton_8 = QtWidgets.QPushButton(self.gridLayoutWidget)
        self.pushButton_8.setObjectName("pushButton_8")
        self.gridLayout.addWidget(self.pushButton_8, 0, 1, 1, 1)
        self.pushButton_4 = QtWidgets.QPushButton(self.gridLayoutWidget)
        self.pushButton_4.setObjectName("pushButton_4")
        self.gridLayout.addWidget(self.pushButton_4, 1, 0, 1, 1)
        self.pushButton_3 = QtWidgets.QPushButton(self.gridLayoutWidget)
        self.pushButton_3.setObjectName("pushButton_3")
        self.gridLayout.addWidget(self.pushButton_3, 2, 2, 1, 1)
        self.pushButton_0 = QtWidgets.QPushButton(self.gridLayoutWidget)
        self.pushButton_0.setObjectName("pushButton_0")
        self.gridLayout.addWidget(self.pushButton_0, 3, 0, 1, 3)
        self.pushButton_2 = QtWidgets.QPushButton(self.gridLayoutWidget)
        self.pushButton_2.setObjectName("pushButton_2")
        self.gridLayout.addWidget(self.pushButton_2, 2, 1, 1, 1)
        self.pushButton_1 = QtWidgets.QPushButton(self.gridLayoutWidget)
        self.pushButton_1.setObjectName("pushButton_1")
        self.gridLayout.addWidget(self.pushButton_1, 2, 0, 1, 1)
        self.pushButton_6.raise_()
        self.pushButton_5.raise_()
        self.pushButton_4.raise_()
        self.pushButton_1.raise_()
        self.pushButton_2.raise_()
        self.pushButton_3.raise_()
        self.pushButton_8.raise_()
        self.pushButton_9.raise_()
        self.pushButton_0.raise_()
        self.pushButton_7.raise_()
    
        self.lcdNumber = QtWidgets.QLCDNumber(Dialog)
        self.lcdNumber.setGeometry(QtCore.QRect(20, 10, 221, 61))
        self.lcdNumber.setObjectName("lcdNumber")
    
        self.gridLayoutWidget_2 = QtWidgets.QWidget(Dialog)
        self.gridLayoutWidget_2.setGeometry(QtCore.QRect(190, 80, 51, 134))
        self.gridLayoutWidget_2.setObjectName("gridLayoutWidget_2")
        self.gridLayout_2 = QtWidgets.QGridLayout(self.gridLayoutWidget_2)
        self.gridLayout_2.setContentsMargins(0, 0, 0, 0)
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.pushButton_10 = QtWidgets.QPushButton(self.gridLayoutWidget_2)
        self.pushButton_10.setObjectName("pushButton_10")
        self.gridLayout_2.addWidget(self.pushButton_10, 2, 0, 1, 1)
        self.pushButton = QtWidgets.QPushButton(self.gridLayoutWidget_2)
        self.pushButton.setObjectName("pushButton")
        self.gridLayout_2.addWidget(self.pushButton, 1, 0, 1, 1)
        self.pushButton_11 = QtWidgets.QPushButton(self.gridLayoutWidget_2)
        self.pushButton_11.setObjectName("pushButton_11")
        self.gridLayout_2.addWidget(self.pushButton_11, 3, 0, 1, 1)
        self.pushButton_12 = QtWidgets.QPushButton(self.gridLayoutWidget_2)
        self.pushButton_12.setObjectName("pushButton_12")
        self.gridLayout_2.addWidget(self.pushButton_12, 0, 0, 1, 1)
        self.label = QtWidgets.QLabel(Dialog)
        self.label.setGeometry(QtCore.QRect(20, 230, 60, 16))
        self.label.setObjectName("label")
    
        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)
    
    
    def my_func(self):
        print("Works")
        self.lcdNumber.display(9)
    
    
    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
        self.pushButton_9.setText(_translate("Dialog", "9"))
        self.pushButton_5.setText(_translate("Dialog", "5"))
        self.pushButton_7.setText(_translate("Dialog", "7"))
        self.pushButton_6.setText(_translate("Dialog", "6"))
        self.pushButton_8.setText(_translate("Dialog", "8"))
        self.pushButton_4.setText(_translate("Dialog", "4"))
        self.pushButton_3.setText(_translate("Dialog", "3"))
        self.pushButton_0.setText(_translate("Dialog", "0"))
        self.pushButton_2.setText(_translate("Dialog", "2"))
        self.pushButton_1.setText(_translate("Dialog", "1"))
        self.pushButton_10.setText(_translate("Dialog", "-"))
        self.pushButton.setText(_translate("Dialog", "+"))
        self.pushButton_11.setText(_translate("Dialog", "="))
        self.pushButton_12.setText(_translate("Dialog", "DEL"))
        self.label.setText(_translate("Dialog", "TextLabel"))
    

    if name == "main":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Dialog = QtWidgets.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())

    1 Reply Last reply
    0
    • S SGaist
      25 Aug 2018, 11:51

      Hi and welcome to devnet,

      What version of Python and PyQt are you using ?

      Just tested here and clicking on the button 9 shows the number 9 on the LCD widget.

      M Offline
      M Offline
      maett1990
      wrote on 25 Aug 2018, 13:13 last edited by
      #3

      @SGaist said in Displaying numbers with QLCDNumber.display() with PyQt5:

      ed here and click

      Hey thanks for the fast reply ;)

      I'm using Python 3.6.3 and PyQt5 (5.11.2)

      The problem i found now is that

      self.lcdNumber.display(9)
      

      doesn't display the number on the display for some unknown reason. I found a workaround with repaint:

      self.lcdNumber.display(9)
      self.lcdNumber.repaint()
      

      Now it works. Maybe a reason for this is that I'm using macOs instead of windows. QT sometimes has different solutions for macOs as far as i can say.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 25 Aug 2018, 11:51 last edited by
        #2

        Hi and welcome to devnet,

        What version of Python and PyQt are you using ?

        Just tested here and clicking on the button 9 shows the number 9 on the LCD widget.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        M 1 Reply Last reply 25 Aug 2018, 13:13
        0
        • S SGaist
          25 Aug 2018, 11:51

          Hi and welcome to devnet,

          What version of Python and PyQt are you using ?

          Just tested here and clicking on the button 9 shows the number 9 on the LCD widget.

          M Offline
          M Offline
          maett1990
          wrote on 25 Aug 2018, 13:13 last edited by
          #3

          @SGaist said in Displaying numbers with QLCDNumber.display() with PyQt5:

          ed here and click

          Hey thanks for the fast reply ;)

          I'm using Python 3.6.3 and PyQt5 (5.11.2)

          The problem i found now is that

          self.lcdNumber.display(9)
          

          doesn't display the number on the display for some unknown reason. I found a workaround with repaint:

          self.lcdNumber.display(9)
          self.lcdNumber.repaint()
          

          Now it works. Maybe a reason for this is that I'm using macOs instead of windows. QT sometimes has different solutions for macOs as far as i can say.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 25 Aug 2018, 13:40 last edited by
            #4

            How did you install PyQt5 ?

            It should not make a difference in this case. Note that I also tested on macOS.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            M 1 Reply Last reply 25 Aug 2018, 14:41
            0
            • S SGaist
              25 Aug 2018, 13:40

              How did you install PyQt5 ?

              It should not make a difference in this case. Note that I also tested on macOS.

              M Offline
              M Offline
              maett1990
              wrote on 25 Aug 2018, 14:41 last edited by
              #5

              @SGaist

              I used this link:
              https://www.riverbankcomputing.com/software/pyqt/download5

              where i also downloades SIP:
              https://www.riverbankcomputing.com/software/sip/download

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 25 Aug 2018, 19:12 last edited by
                #6

                What version of macOS are you using ?

                Did you build PyQt5 yourself ? If so, how did you install Qt ?

                In any case, can you try the version coming from pip ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                M 1 Reply Last reply 26 Aug 2018, 08:11
                0
                • S SGaist
                  25 Aug 2018, 19:12

                  What version of macOS are you using ?

                  Did you build PyQt5 yourself ? If so, how did you install Qt ?

                  In any case, can you try the version coming from pip ?

                  M Offline
                  M Offline
                  maett1990
                  wrote on 26 Aug 2018, 08:11 last edited by
                  #7

                  @SGaist

                  macOs High Sierra (10.13.6)

                  I installed via pip (pip3)

                  maett@Matthiass-MacBook-Pro-2:~/PyQt$ pip install pyqt5
                  Requirement already satisfied: pyqt5 in /Users/maett/anaconda3/lib/python3.6/site-packages (5.11.2)
                  Requirement already satisfied: PyQt5_sip<4.20,>=4.19.11 in /Users/maett/anaconda3/lib/python3.6/site-packages (from pyqt5) (4.19.12)
                  

                  Why are there differences between a Windows menu bar and a macOS one to program?
                  I thought QT should be system independent?
                  Do u know good tutorials combining Qt with OpenCV?

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 26 Aug 2018, 21:12 last edited by
                    #8

                    Except that you have the conda version of the package installed... So right know, which version are you using ?

                    Because both OS does thing differently. Qt goal has always been to provide you with a common code base that behaves according to the OS your application is running on. You can find more information about that in QMenuBar's documentation.

                    You can check that small introduction for OpenCV and Qt

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    M 1 Reply Last reply 27 Aug 2018, 19:36
                    0
                    • S SGaist
                      26 Aug 2018, 21:12

                      Except that you have the conda version of the package installed... So right know, which version are you using ?

                      Because both OS does thing differently. Qt goal has always been to provide you with a common code base that behaves according to the OS your application is running on. You can find more information about that in QMenuBar's documentation.

                      You can check that small introduction for OpenCV and Qt

                      M Offline
                      M Offline
                      maett1990
                      wrote on 27 Aug 2018, 19:36 last edited by
                      #9

                      @SGaist
                      Im not sure if i get the question. I've installed python (3.6.3) via conda and downloaded pyqt5 & sip from riverbank.
                      After installation i checked if it is installed via

                      pip install pyqt5
                      

                      Are there any problems with the conda version of python and Qt? '

                      Thank u soooo much for the links :)

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 27 Aug 2018, 20:42 last edited by
                        #10

                        Since you're using conda, try installing the version that is provided through conda, that will make your environment more coherent.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0

                        1/10

                        25 Aug 2018, 08:52

                        • Login

                        • Login or register to search.
                        1 out of 10
                        • First post
                          1/10
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved