Re: [PyQt] Trouble reading a model index from an untouched combo box
Just took a peak at QAbstractItemView class and your right it's fully implemented. The view is asking the selectionModel what the current selected index is, and if it has no selection model (not sure if that's even possible) it returns an invalid QModelIndex. QComboBox.currentIndex is just asking the QSqlTableModel for the row. It doesn't hurt to make a 1 line code change to test it out. I use QComboBox.currentIndex in my app, though I have no need to change the model in QComboBox. Andreas Pakulat wrote: On 26.01.10 17:41:40, Demetrius Cassidy wrote: I don't think you need to use the view pointer at all - it's returning QAbstractItemView *, which I would assume it would need to be casted to the proper class in C++. If that's so, by design the Abstract class will return an invalid index. I don't think so ;) The function currentIndex on the view is not virtual, so its implemented in the abstract class already properly. And to get a model index to index into the model its easier to ask the view for it, rather than constructing it yourself with model-index( combobox-currentIndex(), model-column, QModelIndex()) Andreas ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Trouble reading a model index from an untouched combo box
2010/1/27 Andreas Pakulat ap...@gmx.de: On 26.01.10 17:41:40, Demetrius Cassidy wrote: I don't think you need to use the view pointer at all - it's returning QAbstractItemView *, which I would assume it would need to be casted to the proper class in C++. If that's so, by design the Abstract class will return an invalid index. I don't think so ;) The function currentIndex on the view is not virtual, so its implemented in the abstract class already properly. And to get a model index to index into the model its easier to ask the view for it, rather than constructing it yourself with model-index( combobox-currentIndex(), model-column, QModelIndex()) Andreas Andreas, That was the way I was thinking when I tried the code in the beggining of this thread.. but I'm still stuck retrieving an invalid index if I don't at least click on the combo box (if I do click on it I get a valid index just fine). If you take a look at the code, my intent was to get the ITEM_ID field, which is the table's primary key which corresponds to the item selected on the combo box. Since I have the model for the table already, I found natural to use it for displaying the ITEM_NAME field on the combo box, so I would get the selected item model index from its view to get the ITEM_ID from the table model and use it to optionally filter data on a subsequent SQL Query. I'm intrigued by this QComboBox behavior, for the model was given a select() before being associated to it, so I think it should return a valid index. Claudio ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] help with qscrollarea for a stacked widget
i am new to pyqt. i have created my gui using Qtdesigner4 now i want to add a vertical scrollbar to stacked widget which is placed on a frame. when i do it as follows the stacked widget forms a new window. i want it in the existing main window. self.scrollarea=QtGui.scrollArea() self.scrollarea.setwidget(self.stackedWidget) self.scrollarea.show() any help appretiated. thanks in advance! ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Error buliding QScintilla 2.2 Python bindings
Hello, I'm trying to build QScintilla 2.2 (same error occurs with 2.3) with Python bindings. I am using Windows MSVC2008, Qt 4.5.3, PyQt4.4.4. QScintilla builds properly. The QScintilla C++ example builds and runs. When running nmake on the Python bindings, it raises an error in the file sipQsciQsciCommandSet.cpp on line 106. Error C2065 'QSciCommandList' : Undeclared identifier. After sifting through some header files, I am unable to find any reference to QsciCommandList. Any ideas? Thanks, Darryl ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Trouble reading a model index from an untouched combo box
On 27.01.10 09:08:13, Claudio Felix wrote: 2010/1/27 Andreas Pakulat ap...@gmx.de: On 26.01.10 17:41:40, Demetrius Cassidy wrote: I don't think you need to use the view pointer at all - it's returning QAbstractItemView *, which I would assume it would need to be casted to the proper class in C++. If that's so, by design the Abstract class will return an invalid index. I don't think so ;) The function currentIndex on the view is not virtual, so its implemented in the abstract class already properly. And to get a model index to index into the model its easier to ask the view for it, rather than constructing it yourself with model-index( combobox-currentIndex(), model-column, QModelIndex()) Andreas Andreas, That was the way I was thinking when I tried the code in the beggining of this thread.. but I'm still stuck retrieving an invalid index if I don't at least click on the combo box (if I do click on it I get a valid index just fine). If you take a look at the code, my intent was to get the ITEM_ID field, which is the table's primary key which corresponds to the item selected on the combo box. Since I have the model for the table already, I found natural to use it for displaying the ITEM_NAME field on the combo box, so I would get the selected item model index from its view to get the ITEM_ID from the table model and use it to optionally filter data on a subsequent SQL Query. I'm intrigued by this QComboBox behavior, for the model was given a select() before being associated to it, so I think it should return a valid index. Well, the combobox has initially no selected/current entry - AFAIK. Only once you select one it'll be set. Hence the invalid index. However a setCurrentIndex with a value != 0 on the combobox should change that already I think. Another thing in your case is that box.view().currentIndex() will not be an index that contains the ITEM_ID value, because the current index will be pointing to the name-cell. Each index indvidually refers to a single cell and you've used the ITEM_NAME column for the combobox, so its view will only give you indexes from that column. Andreas -- You plan things that you do not even attempt because of your extreme caution. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Trouble reading a model index from an untouched combo box
Well, the combobox has initially no selected/current entry - AFAIK. Only once you select one it'll be set. Hence the invalid index. However a setCurrentIndex with a value != 0 on the combobox should change that already I think. Another thing in your case is that box.view().currentIndex() will not be an index that contains the ITEM_ID value, because the current index will be pointing to the name-cell. Each index indvidually refers to a single cell and you've used the ITEM_NAME column for the combobox, so its view will only give you indexes from that column. Andreas Andreas, One of Demetrius' previous suggestions was doing that indeed (setting currentIndex), and I tried it both for zero and non-zero indexes, but to no avail. The combo box starts showing the right item but the model index still comes invalid. If I just click, voila, I get a valid index. Really strange. For this part about getting ITEM_ID, that's the purpose of the getItemID function: def getItemID(self): index = self.comboBox.view().currentIndex() if not index.isValid(): raise ValueError, invalid index # Here I always get the error if I don't click on the combo box before row = index.row() column = self.model.fieldIndex(ITEM_ID) return self.model.data(self.model.index(row, column)).toInt()[0] It retrieves the index corresponding to the ITEM_NAME column in the combo box, but then I query the table model for the same row but specifying the ITEM_ID index, so I really get the right one from the table, not tem combo box. I really think there might be a better way though... the whole purpose of this dialog is to set restrictions on a SQL Query based on the foreign keys found in the main table (each combo box should show a text field associated to a foreign key value), so maybe I can replace the QSqlQuery by a QSqlRelationalTableModel altogether with each combo box showing the named field set through an QSqlRelation. I know that works fine, but if I change a combo box item I suspect it will modify the key value on the main table, and this is not what I want. In fact I just want to filter the results and sum them up in SQL, something like this (consider this table): Volume (float)Cost (float) Supplier_ID (int) Period_ID (int) The query would sum up all the volume and cost records of some product if no Combo box were enabled, but if supplier was enabled it would sum up just the volume and cost for products from a given supplier or if period combo box were enabled also, just the given periods for that given supplier would be considered. Something like select sum(Volume), sum(Cost) from table where SUPPLIER_ID = x and PERIOD_ID = y (the where clause depends on the combos being enabled or not). Thank all you guys for your help! Claudio ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Trouble reading a model index from an untouched combo box
On 27.01.10 17:33:18, Claudio Felix wrote: Well, the combobox has initially no selected/current entry - AFAIK. Only once you select one it'll be set. Hence the invalid index. However a setCurrentIndex with a value != 0 on the combobox should change that already I think. Another thing in your case is that box.view().currentIndex() will not be an index that contains the ITEM_ID value, because the current index will be pointing to the name-cell. Each index indvidually refers to a single cell and you've used the ITEM_NAME column for the combobox, so its view will only give you indexes from that column. Andreas Andreas, One of Demetrius' previous suggestions was doing that indeed (setting currentIndex), and I tried it both for zero and non-zero indexes, but to no avail. The combo box starts showing the right item but the model index still comes invalid. If I just click, voila, I get a valid index. Really strange. Looking at the source code in Qt, I think the reason for this is because there's no connection between the currentIndex() in the itemview and the one in its selectionModel. In particular the currentChanged() slot in the itemview doesn't update its internal currentIndex. I think thats a bug in Qt. So you'll have to ignore the view here and work with the row from the combobox to generate a model index. This should work: def getItemID(self: self.comboBox.setCurrentIndex(0) idx = self.model.index( self.comboBox.currentIndex(), self.model.fieldIndex(ITEM_ID), QModelIndex() ) return self.model.data(idx).toInt()[0] Andreas -- You are a bundle of energy, always on the go. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Fix: layoutStretch property is not compiled by pyuic4
The layoutStretch property of QHBoxLayout and QVBoxLayout in designer should be compiled to layout.setStretch() calls. The code to do this is already present in PyQt4.uic.uiparser, but never triggered because of an error in the types hierarchies defined in PyQt4.uic.Compiler.qtproxies (QHBoxLayout and QVBoxLayout should be descendants of QBoxLayout instead of QLayout). Attached is a patch (made against PyQt-x11-gpl-4.7.1-snapshot-20100120.tar.gz) and a .ui file showing the issue. -- Lup layoutStretch_example.ui Description: application/designer --- uic/Compiler/qtproxies.py 2010-01-21 04:36:58.0 +0100 +++ /usr/lib/python2.6/dist-packages/PyQt4/uic/Compiler/qtproxies.py 2010-01-28 01:38:30.864992872 +0100 @@ -237,8 +237,9 @@ class QButtonGroup(QtCore.QObject): pass class QLayout(QtCore.QObject): pass class QGridLayout(QLayout): pass -class QHBoxLayout(QLayout): pass -class QVBoxLayout(QLayout): pass +class QBoxLayout(QLayout): pass +class QHBoxLayout(QBoxLayout): pass +class QVBoxLayout(QBoxLayout): pass class QFormLayout(QLayout): pass class QWidget(QtCore.QObject): ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt