<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-GB link="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal>I am trying to write a data driven application in PYQT4 with PostgreSQL. This is new to me but it seems like it should be straightforward. I am sure that this is a newbie question but I can't seem to find the answer from my friend Google. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>My problem is I have set up a QtableView which populates fine and looks good. Column 2 contains a primary key for a record. In the manor of a classic pick list, I would like the user to click on it and open a form to edit the record. I can't seem to figure out how to get the value in the hidden column of the clicked on row to use in the WHERE clause to set the model for the form to open. Code is below.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Thanks for any help!<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>from PyQt4.QtCore import *<o:p></o:p></p><p class=MsoNormal>from PyQt4.QtGui import *<o:p></o:p></p><p class=MsoNormal>from PyQt4.QtSql import *<o:p></o:p></p><p class=MsoNormal>import sys<o:p></o:p></p><p class=MsoNormal>from ci_co_table import *<o:p></o:p></p><p class=MsoNormal>from guest_info_form import *<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>class Ci_Co(QMainWindow):<o:p></o:p></p><p class=MsoNormal> """Check in and check out module"""<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal> def __init__(self, parent=None):<o:p></o:p></p><p class=MsoNormal> QWidget.__init__(self, parent)<o:p></o:p></p><p class=MsoNormal> self.ui = Ui_MainWindow()<o:p></o:p></p><p class=MsoNormal> self.ui.setupUi(self)<o:p></o:p></p><p class=MsoNormal> global hotdate<o:p></o:p></p><p class=MsoNormal> qry_params = QSqlQuery()<o:p></o:p></p><p class=MsoNormal> qry_params.exec_("select param_date from params where id = 1")<o:p></o:p></p><p class=MsoNormal> param_date = 0<o:p></o:p></p><p class=MsoNormal> while qry_params.next():<o:p></o:p></p><p class=MsoNormal> hotdate = unicode(qry_params.value(param_date).toString())<o:p></o:p></p><p class=MsoNormal> print(hotdate)<o:p></o:p></p><p class=MsoNormal> self.ui.hotdate_lbl.setText(hotdate)<o:p></o:p></p><p class=MsoNormal> self.populate_mainform()<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal> def populate_mainform(self):<o:p></o:p></p><p class=MsoNormal> arrivals_model = QSqlQueryModel()<o:p></o:p></p><p class=MsoNormal> arrivals_model.setQuery("select rooms.room, bookings.label, bookings.booking_id from bookings LEFT JOIN rooms ON bookings.room_id = rooms.hls_code where arrival_date = '{0}' and checked_in is Null and cancelled is Null order by to_number(rooms.room, text(99))".format(hotdate))<o:p></o:p></p><p class=MsoNormal> self.arrivals_view = self.ui.arrivals<o:p></o:p></p><p class=MsoNormal> self.arrivals_view.setModel(arrivals_model) <o:p></o:p></p><p class=MsoNormal> self.arrivals_view.setColumnHidden(2, True)<o:p></o:p></p><p class=MsoNormal> self.arrivals_view.setSelectionBehavior(QTableView.SelectRows)<o:p></o:p></p><p class=MsoNormal> self.arrivals_view.setSortingEnabled(True)<o:p></o:p></p><p class=MsoNormal> QObject.connect(self.arrivals_view, SIGNAL("clicked(QModelIndex)"), self.ci_clicked)<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal> def ci_clicked(self, QModelIndex):<o:p></o:p></p><p class=MsoNormal> self.gst_form = Guest_form(self)<o:p></o:p></p><p class=MsoNormal> self.gst_form.show()<o:p></o:p></p><p class=MsoNormal> guest_model = QSqlQueryModel()<o:p></o:p></p><p class=MsoNormal> guest_model.setQuery("select * from bookings LEFT JOIN rooms ON bookings.room_id = rooms.hls_code WHERE id = '{0}'".format(""))<o:p></o:p></p><p class=MsoNormal> #map widgets here<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal>class Guest_form(QDialog, Ui_guest_info_form):<o:p></o:p></p><p class=MsoNormal> def __init__(self, parent=None):<o:p></o:p></p><p class=MsoNormal> #super(Guest_form, self).__init__(parent)<o:p></o:p></p><p class=MsoNormal> QDialog.__init__(self, parent)<o:p></o:p></p><p class=MsoNormal> self.setupUi(self)<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>if __name__=="__main__":<o:p></o:p></p><p class=MsoNormal> app=QtGui.QApplication(sys.argv)<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal> #Database stuff<o:p></o:p></p><p class=MsoNormal> db = QSqlDatabase.addDatabase("QPSQL");<o:p></o:p></p><p class=MsoNormal> db.setHostName("my_host_name")<o:p></o:p></p><p class=MsoNormal> db.setDatabaseName("my_db");<o:p></o:p></p><p class=MsoNormal> db.setUserName("me");<o:p></o:p></p><p class=MsoNormal> db.setPassword("my_password");<o:p></o:p></p><p class=MsoNormal> if (db.open()==False): <o:p></o:p></p><p class=MsoNormal> QMessageBox.critical(None, "Database Error", db.lastError().text())<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal> myapp = Ci_Co()<o:p></o:p></p><p class=MsoNormal> myapp.show()<o:p></o:p></p><p class=MsoNormal> sys.exit(app.exec_())<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='font-family:"Arial",sans-serif;mso-fareast-language:EN-GB'>Dave Kelly<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Arial",sans-serif;mso-fareast-language:EN-GB'><a href="http://theprioryinn.co.uk/">The Priory Inn</a><o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Arial",sans-serif;mso-fareast-language:EN-GB'>01666 502 251<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Arial",sans-serif;mso-fareast-language:EN-GB'>London Road, Tetbury, GL8 8JJ<o:p></o:p></span></p><p class=MsoNormal><i><span style='font-family:"Arial",sans-serif;mso-fareast-language:EN-GB'>"Dining in a 30 mile food zone"<o:p></o:p></span></i></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>