Readonly Model implementation requirements for QComboBox
Hi @all,
I'm implementing a model by sub classing QAbstractTableModel.
The model is read-only.
I did implement the methods rowCount(), columnCount() and data().
Using this model with a QComboBoxcauses one problem: The listview is not popping up.
I was already walking through the QComboBox implementation in order to see what might cause this - but I have absolutely NO idea ....
Anyone an idea???
THX alot
Re: Readonly Model implementation requirements for QComboBox
Hi, could you check if i.e. QTableView shows some contents? If QTableView or ListView is also empty, post code of your inherited model.
Oh... one more thing - make sure you have setModel for comboBox...
Re: Readonly Model implementation requirements for QComboBox
The content is loaded to the combo box, because I see the content combobox and
by pressing the up and down arrows I can navigate through the items.
The only trouble is the listview is not popping up. :crying:
Re: Readonly Model implementation requirements for QComboBox
Did you subclass QComboBox? Did you reimplement any of its event handlers or so? I made a simple test and it works fine for me:
Code:
#include <QtGui>
{
public:
TableModel
(int rows,
int cols,
QObject* parent
= 0)
int rowCount
(const QModelIndex
& parent
= QModelIndex()) const { return rows;
} int columnCount
(const QModelIndex
& parent
= QModelIndex()) const { return cols;
}
QVariant data
(const QModelIndex
& index,
int role
= Qt
::DisplayRole) const {
if (index.isValid() && role == Qt::DisplayRole)
return QString("%1,%2").
arg(index.
row()).
arg(index.
column());
}
private:
int rows;
int cols;
};
int main(int argc, char *argv[])
{
combo.setModel(new TableModel(5, 2, &combo));
combo.show();
return app.exec();
}
Re: Readonly Model implementation requirements for QComboBox
Thanks for the small demo code.
I had a bug in the data() implementation where I did not pay enough attention to the role.
THX
Re: Readonly Model implementation requirements for QComboBox
Quote:
Originally Posted by
DeepDiver
Thanks for the small demo code.
You're welcome :)
Quote:
I had a bug in the data() implementation where I did not pay enough attention to the role.
I'm curious. What kind of bug? The side effect (even if data is shown in table, combo popup is not shown) is confusing..
Re: Readonly Model implementation requirements for QComboBox
I was always returning the cell data.
Something like:
Code:
if (!index.isValid())
if (role == Qt::DecorationRole)
switch(index.column())
{
case 0: return "col0";
case 1: return "col1";
case 2: return "col2";
...
}
What does that mean?
I return a string for the role Qt::SizeHintRole - which causes each item to have a size of 0.
That's why the list view has a total height of 0 as well.
:crying:
Again THX a lot!