Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- # Allow access to command-line arguments
- import sys
- # Import the core and GUI elements of Qt
- from PySide.QtCore import *
- from PySide.QtGui import *
- # Create the QApplication object
- qt_app = QApplication(sys.argv)
- #Hier wird das Hauptfenster erzeugt und alle Signal-/Slot Verbindungen werden aufgebaut.
- class Mainwindow(QWidget):
- def __init__(self):
- # Initialize the object as a QWidget and
- # set its title and minimum width
- QWidget.__init__(self)
- self.setWindowTitle('Einfache Applikation')
- self.setMinimumWidth(300)
- self.setMinimumHeight(200)
- # Erstellung einer H-Box welche die hinzugefuegten Widgets nebeneinander anordnet
- self.hboxlayout = QHBoxLayout()
- self.listWidget = QListWidget()
- self.hboxlayout.addWidget(self.listWidget)
- self.vboxlayout=QVBoxLayout()
- self.aButton=QPushButton('ADD', self)
- self.vboxlayout.addWidget(self.aButton)
- self.dButton=QPushButton('Delete', self)
- self.vboxlayout.addWidget(self.dButton)
- self.cButton=QPushButton('Clear', self)
- self.vboxlayout.addWidget(self.cButton)
- self.vboxlayout.addStretch()
- self.hboxlayout.addLayout(self.vboxlayout)
- self.aButton.clicked.connect(self.on_aButton_clicked)
- self.dButton.clicked.connect(self.on_dButton_clicked)
- self.cButton.clicked.connect(self.on_cButton_clicked)
- self.setLayout(self.hboxlayout)
- #In diesem Slot wird das "clicked"-Signal des Buttons verarbeitet
- @Slot()
- def on_aButton_clicked(self):
- nText=QInputDialog.getText(self, "Eingabe", "text")
- if not (nText==""):
- item=QListWidgetItem(self.listWidget)
- item.setText(nText[0])
- def on_dButton_clicked(self):
- for item in self.listWidget.selectedItems():
- self.listWidget.takeItem(self.listWidget.row(item))
- def on_cButton_clicked(self):
- self.listWidget.clear()
- def run(self):
- # Show the form
- self.show()
- # Run the qt application
- qt_app.exec_()
- def main():
- # Create an instance of the application window and run it
- app = Mainwindow()
- app.run()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement