How do i check if the user has selected an item in my qlistwidget? i could not find any resources elsewhere.
this is what i want to achieve:
if an item has not been selected when the user presses the delete button. then a message box should appear saying please select an item.
this is my delete function for the delete button
def delete_it(self):
# create a data base or connect to one
conn = sqlite3.connect('ab.db')
# create a cursor
c = conn.cursor()
symbol = self.i_listwidget.currentItem().text()
clicked = self.i_listwidget.currentRow()
self.i_listwidget.takeItem(clicked)
c.execute("DELETE FROM tone WHERE first_name = '%s'" % symbol)
# commit the changes
conn.commit()
# close our connection
conn.close()
I do know how to convert a school year into your age, that is country specify.
Qt, via PyQt, is an amazing tool for making GUI programs.
You are asking about the selection in the QListWidget.
On the page I pointed you to you will find that it documents a function to get the selected items.
I wanted to check if the item was selected by the user so i could put up a yes and no message box to double check if the user wanted to delete the item from the data base. When you told me to use ‘.’ instead of ‘:’ i used another piece of code and it was the solution for my problem:
def delete_it(self):
msgBox = QMessageBox()
msgBox.setWindowTitle("title")
msgBox.setText("Question")
msgBox.setStandardButtons(QMessageBox.Yes)
msgBox.addButton(QMessageBox.No)
msgBox.setDefaultButton(QMessageBox.No)
if(msgBox.exec() == QMessageBox.Yes):
print("1")
# create a data base or connect to one
conn = sqlite3.connect('ab.db')
# create a cursor
c = conn.cursor()
symbol = self.i_listwidget.currentItem().text()
clicked = self.i_listwidget.currentRow()
self.i_listwidget.takeItem(clicked)
c.execute("DELETE FROM tone WHERE first_name = '%s'" % symbol)
# commit the changes
conn.commit()
# close our connection
conn.close()
# clear the item box
self.fn_lineedit.setText("")
self.ln_lineedit.setText("")
self.pn_lineedit.setText("")
self.ea_lineedit.setText("")
self.a_textedit.setText("")
self.close_pushbutton.setEnabled(False)
self.save_pushbutton.setEnabled(False)
self.disable()
self.disable_dd()
self.disable_u()
self.disable_c()
else:
pass