Python PyQt5:我还可以通过SQL将QPushButton插入数据库吗?

时间:2021-02-01 23:02:11

As the title suggests I want to know if it's possible to insert a QPushButton into a database via SQL?

正如标题所示,我想知道是否可以通过SQL将QPushButton插入数据库?

    connection = pymysql.connect(host = 'localhost',
        user = 'root',
        db = 'myDatabase',
        cursorclass = pymysql.cursors.DictCursor)  
    cur = connection.cursor()

    cur.execute("INSERT INTO myTable VALUES("%s"), [QPushButton("Click me!")])  

1 个解决方案

#1


2  

If you're using a QTableWidget to display the database, you need to add the button to the cell in the table:

如果您使用QTableWidget显示数据库,则需要将按钮添加到表格中的单元格:

    button = QPushButton('Show Image', self)
    button.clicked.connect(self.handleImageButton)
    self.tableWidget.setCellWidget(row, column, button)
    ...

def handleImageButton(self):
    button = self.sender()
    item = self.tableWidget.itemAt(button.pos())
    if item is not None:
        print(item.row(), item.column())
        # get image data, etc ...

#1


2  

If you're using a QTableWidget to display the database, you need to add the button to the cell in the table:

如果您使用QTableWidget显示数据库,则需要将按钮添加到表格中的单元格:

    button = QPushButton('Show Image', self)
    button.clicked.connect(self.handleImageButton)
    self.tableWidget.setCellWidget(row, column, button)
    ...

def handleImageButton(self):
    button = self.sender()
    item = self.tableWidget.itemAt(button.pos())
    if item is not None:
        print(item.row(), item.column())
        # get image data, etc ...