vitorlobo 0 Newbie Poster

Hi Guys!

I'm new to the forum and I have a doubt. Who can help me, I thank you.


This is a simple GUI .. formed by a simple table. How do I connect to a database file. Db so that is shown in table QtGui? I'm using SQLite in python.

GUI - Download

DB - Download

# -*- coding: utf-8 -*-


import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *

class Ui_MainWindow(object):
    def __init__(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(370, 320)
        
        self.centralwidget = QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        
        self.VLayout_central = QVBoxLayout(self.centralwidget)
        self.VLayout_central.setObjectName("VLayout_central")
        
        self.DBTable = QTableWidget(self.centralwidget)
        self.DBTable.setRowCount(10)
        self.DBTable.setColumnCount(2)
        self.DBTable.setObjectName("DBTable")
        self.DBTable.setColumnCount(2)
        self.DBTable.setRowCount(10)
        self.DBTable.horizontalHeader().setDefaultSectionSize(152)
        
        self.VLayout_central.addWidget(self.DBTable)
        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)
        QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
		
		utf8code = QApplication.UnicodeUTF8
		MainWindow.setWindowTitle(QApplication.translate("MainWindow", "DbTableTest", None,utf8code))


if __name__ == "__main__":
    app = QApplication(sys.argv)
    MainWindow = QMainWindow()
    ui = Ui_MainWindow(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.