Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, April 2008
Widgets and delegates -- a problem


Message 1 in thread

Greetings,

I have a table (an SQL view to be exact) which I want to display using custom widgets, one per row. The documentation suggests that I use something like QListView and have a delegate paint widgets 
instead of standard controls. However, that fails to work.

I have:

ui.results->setModel(m_modelResults);
ui.results->setItemDelegate(new PropertyWidgetDelegate(ui.results));

where m_modelResults is a QSqlQueryModel and PropertyWidgetDelegate inherits QItemDelegate with overrides as simple as:

QWidget* PropertyWidgetDelegate::createEditor(QWidget* parent, QStyleOptionViewItem const &, QModelIndex const &) const
{
    return new PropertyWidget(m_dm, m_pp.get(), parent); // be this correct or not, it never gets called
}

void PropertyWidgetDelegate::setEditorData(QWidget* editor, QModelIndex const& index) const
{
    dncast<PropertyWidget *>(editor)->setIndex(index); // the same for this method
}

These never get called, and I get a list of the values of the first column of the table, or the entire table if I use a QTableView insteadâas though no delegate were specifiedâwhile I expected my custom 
widgets to appear.

What is the correct way to display as many widgets as there are rows in a table, having each widget populate itself with data from the corresponding row? I only need read access to the table.

TIA, Roman.

Attachment:

Attachment: smime.p7s
Description: S/MIME cryptographic signature


Message 2 in thread

So, it turns out that the widgets provided by delegates are only visible after one clicks on a field of a view. Is there a way to make them visible all the time, or another way to compose a view from custom 
widgets?

Attachment:

Attachment: smime.p7s
Description: S/MIME cryptographic signature


Message 3 in thread

Am Montag, 21. April 2008 schrieb Roman Odaisky:
> I have a table (an SQL view to be exact) which I want to display using
> custom widgets, one per row. The documentation suggests that I use
> something like QListView and have a delegate paint widgets instead of
> standard controls. However, that fails to work.

The docs to QAbstractItemDelegate are pretty clear on that:

"To render an item in a custom way, you must implement paint() and sizeHint(). 
The QItemDelegate class provides default implementations for these functions; 
if you do not need custom rendering, subclass that class instead."

So you have to implement sizeHint() to get custom sizes. And you have to 
implement paint() to have custom displaying of your data.

The other functions are for custom data-editing...

Have fun,

Arnold
-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: This is a digitally signed message part.