Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Understand the logic of a simple pyqt5 interface inside a script

Understand the logic of a simple pyqt5 interface inside a script

Scheduled Pinned Locked Moved Unsolved Qt for Python
1 Posts 1 Posters 311 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.
  • O Offline
    O Offline
    otaolafr
    wrote on last edited by
    #1

    Hello,
    I have a python script which does calculations, and from the results it shows an interface (created using pyqt5) that shows part of this information using QLineEdit, allows to call some functions (to do some calculations) and then if accepted continue the code.
    I am not used to object oriented programation so I did this as I have learned to program (my excuses for the veterans out there) , that it is not python style at all. while browsing over internet for tutorials on how to do a windows dialog using pyqt5, several of them use a class to define the function,etc, if possible I would like some feedback of why going that route and if possible, for a simple case like the one I put in the script below, to 'translate' it to the class style so I can construct and understand from that.

    from PyQt5.QtWidgets import QWidget, QMessageBox
    from PyQt5 import QtCore, QtGui
    import PyQt5.QtCore as QtCore
    from PyQt5.QtWidgets import *
    from PyQt5.QtCore import Qt
    
    listOfValues=[1,2,3,4]
    
    finalResults=[[] for x in range(len(listOfValues))]
    def hideDisplay():
        dialog.hide()
    
    def clicked():
        for i in range(len(listOfValues)):
            inputsLines_0[i].setText(str(int(inputsLines_0[i].text())+1))
    
    def printFunction():
        for i in range(len(inputsLines_0)):
           finalResults[i]=int(inputsLines_0[i].text())
            
    dialog = QDialog()
    dialog.setWindowTitle("Input size")
    layout_0 = QGridLayout(dialog)
    inputsLines_0=[]
    
    for i in range(len(listOfValues)):
        inputsLines_0.append(QLineEdit(str(listOfValues[i])))
        layout_0.addWidget(inputsLines_0[i],0,i)
    
    addButton=QPushButton("+1")
    layout_0.addWidget(addButton,0,len(listOfValues)+1)
    
    addButton.clicked.connect(clicked)
    
    okbox = QDialogButtonBox(dialog)
    okbox.setOrientation(QtCore.Qt.Horizontal)
    okbox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok)
    
    okbox.accepted.connect(printFunction)
    okbox.rejected.connect(hideDisplay)
    layout_0.addWidget(okbox,1,0)
    
    1 Reply Last reply
    0

    • Login

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