[PyQt] QTableView as pick list

Dave Kelly dave at theprioryinn.co.uk
Wed Dec 2 10:57:05 GMT 2015


Hi,

 

I am sorry but I am still stuck.  I updated my code with:

 

    def ci_clicked(self, model_index):

        whoami = self.arrivals_view.model().index(model_index, 2).data()

        self.gst_form = Guest_form(self)

        self.gst_form.show()

        guest_model = QSqlQueryModel()

        guest_model.setQuery("select * from bookings LEFT JOIN rooms ON bookings.room_id = rooms.hls_code WHERE id = '{0}'".format(whoami))

            

It drops out with an error:

 

File "F:\Dropbox\pms\main.py", line 120, in <module>

  sys.exit(app.exec_())

File "F:\Dropbox\pms\main.py", line 89, in ci_clicked

  whoami = self.arrivals_view.model().index(model_index, 2).data()

 

TypeError: QAbstractTableModel.index(int, int, QModelIndex parent=QModelIndex()): argument 1 has unexpected type 'QModelIndex'

 

 

model_index is being passed because if I put print(model_index.row()) into the code it comes up with the correct row.  There is something about the type of model_index.

 

PYQT_VERSION_STR gives '4.11.4'

sys.version '2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)]'

 

Thanks again.  I am grateful for your patience with this beginner.

 

 

Dave Kelly

The Priory Inn <http://theprioryinn.co.uk/> 

01666 502 251

London Road, Tetbury, GL8 8JJ

"Dining in a 30 mile food zone"

 

From: Kernc [mailto:kerncece at gmail.com] 
Sent: 01 December 2015 15:11
To: Dave Kelly <dave at theprioryinn.co.uk>
Cc: pyqt at riverbankcomputing.com
Subject: Re: [PyQt] QTableView as pick list

 

Q*Model-s store the data; Q*View-s only present it.

The string data of the hidden second column should be:


    self.arrivals_view.model().index(model_index, 2).data()

with model_index being the second parameter to ci_clicked().

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20151202/36e7f5e1/attachment.html>


More information about the PyQt mailing list