![]() |
2010-03-24
, 08:30
|
Posts: 3,319 |
Thanked: 5,610 times |
Joined on Aug 2008
@ Finland
|
#2
|
The Following User Says Thank You to attila77 For This Useful Post: | ||
![]() |
2010-03-24
, 09:45
|
Posts: 278 |
Thanked: 209 times |
Joined on Dec 2009
|
#3
|
![]() |
2010-03-24
, 10:11
|
Posts: 3,319 |
Thanked: 5,610 times |
Joined on Aug 2008
@ Finland
|
#4
|
import sys from PyQt4 import QtCore, QtGui, QtSql def createConnection(): db = QtSql.QSqlDatabase.addDatabase("QSQLITE") db.setDatabaseName(":memory:") if not db.open(): QtGui.QMessageBox.critical(None, QtGui.qApp.tr("Cannot open database"), QtGui.qApp.tr("Unable to establish a database connection.\n" "This example needs SQLite support. Please read " "the Qt SQL driver documentation for information " "how to build it.\n\nClick Cancel to exit."), QtGui.QMessageBox.Cancel, QtGui.QMessageBox.NoButton) return False query = QtSql.QSqlQuery() query.exec_("create table person(id int primary key, " "firstname varchar(20), lastname varchar(20))") query.exec_("insert into person values(101, 'Danny', 'Young')") query.exec_("insert into person values(102, 'Christine', 'Holand')") query.exec_("insert into person values(103, 'Lars', 'Gordon')") query.exec_("insert into person values(104, 'Roberto', 'Robitaille')") query.exec_("insert into person values(105, 'Maria', 'Papadopoulos')") return True def initializeModel(model): model.setTable("person") model.setEditStrategy(QtSql.QSqlTableModel.OnManualSubmit) model.select() model.setHeaderData(0, QtCore.Qt.Horizontal, QtCore.QVariant(QtCore.QObject.tr(model, "ID"))) model.setHeaderData(1, QtCore.Qt.Horizontal, QtCore.QVariant(QtCore.QObject.tr(model, "First name"))) model.setHeaderData(2, QtCore.Qt.Horizontal, QtCore.QVariant(QtCore.QObject.tr(model, "Last name"))) def createView( title, model ): view = QtGui.QTableView() view.setModel(model) view.setWindowTitle(title) return view if __name__ == "__main__": app = QtGui.QApplication(sys.argv) if not createConnection(): sys.exit(1) model = QtSql.QSqlTableModel() initializeModel(model) view1 = createView(model.tr("Table Model (View 1)"), model) view2 = createView(model.tr("Table Model (View 2)"), model) view1.show() view2.move(view1.x() + view1.width() + 20, view1.y()) view2.show() sys.exit(app.exec_())
The Following User Says Thank You to attila77 For This Useful Post: | ||
![]() |
2010-03-24
, 11:51
|
Posts: 278 |
Thanked: 209 times |
Joined on Dec 2009
|
#5
|
![]() |
2010-03-24
, 13:22
|
Posts: 3,319 |
Thanked: 5,610 times |
Joined on Aug 2008
@ Finland
|
#6
|
I already did the Hello World. It's just a label. then you make the .ui into a .py and execute that.
HOWEVER, the insert statements and views are static. what if I want the Insert to take a value from a lineEdit box? What will be
the story of the slots/receive/sender then? Lets say I want the results to display inside a GUI i made, not to spontaneously pop up like the example code?
I've looked online, but I couldn't find a guide that told me everything from start to finish....and there are gaps between the guides out there.....
Can someone please just give me 1 detailed example? just 1 simple one?
(For Now) I want an app with one button, one line edit.
This button will simply insert the text in the line into a column in a MySQL database.on a server, in the same network.
Once I see that done from start to finish. I can build on it.......
I have Python 2.6 and PyQT4 Designer Installed.....I made the UI....(attached)
But I'm COMPLETELY clueless of what to do with signals or slots....or whats the connection code........or How to compile it into a working program.....
Can someone please please please help me? please be as DETAILED as you can.....I'm clueless......
Attachment 8335