Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. # Allow access to command-line arguments
  4.  
  5. import sys
  6.  
  7. # Import the core and GUI elements of Qt
  8. from PySide.QtCore import *
  9. from PySide.QtGui import *
  10.  
  11. # Create the QApplication object
  12. qt_app = QApplication(sys.argv)
  13.  
  14. #Hier wird das Hauptfenster erzeugt und alle Signal-/Slot Verbindungen werden aufgebaut.
  15. class Mainwindow(QWidget):
  16. def __init__(self):
  17.  
  18. # Initialize the object as a QWidget and
  19. # set its title and minimum width
  20. QWidget.__init__(self)
  21. self.setWindowTitle('Einfache Applikation')
  22. self.setMinimumWidth(300)
  23. self.setMinimumHeight(200)
  24.  
  25. # Erstellung einer H-Box welche die hinzugefuegten Widgets nebeneinander anordnet
  26. self.hboxlayout = QHBoxLayout()
  27.  
  28. self.listWidget = QListWidget()
  29. self.hboxlayout.addWidget(self.listWidget)
  30.  
  31. self.vboxlayout=QVBoxLayout()
  32. self.aButton=QPushButton('ADD', self)
  33. self.vboxlayout.addWidget(self.aButton)
  34. self.dButton=QPushButton('Delete', self)
  35. self.vboxlayout.addWidget(self.dButton)
  36. self.cButton=QPushButton('Clear', self)
  37. self.vboxlayout.addWidget(self.cButton)
  38. self.vboxlayout.addStretch()
  39. self.hboxlayout.addLayout(self.vboxlayout)
  40.  
  41. self.aButton.clicked.connect(self.on_aButton_clicked)
  42. self.dButton.clicked.connect(self.on_dButton_clicked)
  43. self.cButton.clicked.connect(self.on_cButton_clicked)
  44.  
  45. self.setLayout(self.hboxlayout)
  46.  
  47. #In diesem Slot wird das "clicked"-Signal des Buttons verarbeitet
  48. @Slot()
  49. def on_aButton_clicked(self):
  50. nText=QInputDialog.getText(self, "Eingabe", "text")
  51. if not (nText==""):
  52. item=QListWidgetItem(self.listWidget)
  53. item.setText(nText[0])
  54. def on_dButton_clicked(self):
  55. for item in self.listWidget.selectedItems():
  56. self.listWidget.takeItem(self.listWidget.row(item))
  57.  
  58. def on_cButton_clicked(self):
  59. self.listWidget.clear()
  60.  
  61. def run(self):
  62. # Show the form
  63. self.show()
  64. # Run the qt application
  65. qt_app.exec_()
  66.  
  67. def main():
  68. # Create an instance of the application window and run it
  69. app = Mainwindow()
  70. app.run()
  71.  
  72. if __name__ == '__main__':
  73. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement