After a little work, I think I solved the first issues i've had, thanks Denni!
Soon I might start fishing myself
Soon I might start fishing myself
USE_PYSIDE2 = False if USE_PYSIDE2: from PySide2.QtCore import Signal, Slot from PySide2.QtWidgets import QApplication, QVBoxLayout from PySide2.QtWidgets import QListWidget, QMessageBox else: from PyQt5.QtCore import pyqtSignal as Signal from PyQt5.QtCore import pyqtSlot as Slot from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout from PyQt5.QtWidgets import QListWidget, QMessageBox class MyWindow(QWidget): def __init__(self): # Do not use Super( ) it was made to handle a specific issue that # rarely occurs and if you are not experiencing that rather specific # issue you are adding more potential issues by using Super( ) and # making your program more complex than it needs to be QWidget.__init__(self) Top = 150;Left = 200;Width=250;Hight=200 self.setGeometry(Top,Left,Width,Hight) self.setWindowTitle('APL-Besök') # Skapa listkontroll self.lstDates = QListWidget(self) # Lägg till alternativ i listan ItemsForListBox = self.GetDateList() self.lstDates.addItems(ItemsForListBox) # Sätt standardalternativet till rad 0 self.lstDates.setCurrentRow(2) # Koppla en händelsemetod till signal self.lstDates.currentRowChanged.connect(self.OnCurrentRowChanged) VBox = QVBoxLayout() VBox.addWidget(self.lstDates) self.setLayout(VBox) # While you can get away with not using the Slot decorator it can cause # issues and not using it is just lazy coding @Slot(int) def OnCurrentRowChanged(self, RowNum, next_visit=10): # If doing simple debugging or proof of concept prints are simpler # Messagebox that returns next visit NextVisit = self.GetDateList() QMessageBox.information(self, "APL-nästa :", " Nästa besök " +str(NextVisit[NextVisit.index(self.lstDates.item(RowNum).text())+10] )) print('Meddelande : Senaste besöket : ',RowNum,) print('Meddelande : Nästa besök : ',self.lstDates.currentItem().text()) print('Using the RowNum to Get Item Value ',self.lstDates.item(RowNum).text()) # Hantera signalen currentRowChanged # Using str(Curr) might not get you want you want to know -- best to always just print # the raw value (as done above) so you know exactly what you are getting # QMessageBox.information(self, "Meddelande", "Senaste besöket: " + str(Curr)) # QMessageBox.information(self, "Meddelande", "Nästa besök: " + self.list_box.currentItem().text()) def GetDateList(self): # Doing it this way so that how this List gets generated can be done as needed # without affecting the basic flow of the program DateList = ['2019-10-14','2019-10-15','2019-10-16','2019-10-17','2019-10-18','2019-10-21','2019-10-22','2019-10-23','2019-10-24','2019-10-25','2019-11-07','2019-11-08','2019-11-14','2019-11-15','2019-11-21','2019-11-28','2019-11-29','2019-12-05','2019-12-06','2019-12-12','2019-12-13','2019-12-16','2019-12-17','2019-12-18','2019-12-19','2020-01-15','2020-01-16','2020-01-23','2020-01-24','2020-01-30','2020-01-31','2020-02-06','2020-02-07','2020-02-13','2020-02-14','2020-02-17','2020-02-18','2020-02-19','2020-02-20','2020-02-21','2020-03-02','2020-03-03','2020-03-04','2020-03-05','2020-03-06','2020-03-09','2020-03-10','2020-03-11','2020-03-12','2020-03-13','2020-03-19','2020-03-20','2020-03-26','2020-03-27','2020-04-02','2020-04-03','2020-04-09','2020-04-24','2020-04-30','2020-05-07','2020-05-08','2020-05-15','2020-05-25','2020-05-26','2020-05-27','2020-05-28','2020-05-29','2020-06-01','2020-06-02','2020-06-03','2020-06-04','2020-06-05'] return DateList.copy() if __name__ == '__main__': # If not using Command Line arguments then you do not need sys.argv # and if using Command Line arguments use argparser library instead MainEventThread = QApplication([]) MainApp = MyWindow() MainApp.show() # This is the Qt5 way of handling it now MainEventThread.exec()