Qt-jambi-interest Archive, October 2006
Custom QTableView
Message 1 in thread
Hi,
Recently I have implimented a custom widget that allows multiple QTableViews
to be included and managed as a single widget. The tables are split up into
separate "sections" and items can be added to each section. You can select
the width of the columns, give them headers and set wether the content can be
edited.
In order to achieve some of the functionality I have extended
QAbstractItemModel and QItemDelegate.
The code needs a lot of cleaning up and some classes should probably be
merged. This could serve as a reference for anyone looking for an example on
how to extend the Model/View system Qt uses (and probably a reference on how
not to code GUI components)
I am having one problem. With my current implementation of it I reload all
the data into the Widget if some info has changed. For longer lengths of
lists, this incurse a noticeable delay. setUpdatesEnabled doesn't appear to
help. Any advice will be most welcome.
I hope this helps, somehow
David
Following is an example of usages:
// Constructor
pair = new MultiWidget(ui.fmScores, MultiWidget.EXPANDING,
MultiWidget.MINIMUM | MultiWidget.EDITABLE,
MultiWidget.EXPANDING);
pair.setHeader("Partner", "Score", "Partner");
pair.setSelectRow(false);
ui.fmScores.setWidget(pair);
pair.editedData.connect(this, "edited(Data,int)");
// Methods
private void refreshList()
{
List<Data> sorted = pairs.getAll();
Collections.sort(sorted);
int section = 0;
Iterator<Data> next = sorted.iterator();
pair.clear();
while(next.hasNext())
{
Pair n = (Pair)next.next();
if(section != n.section())
{
section = n.section();
pair.addSection("Section: " + (char)(64 + section));
}
Member p1 = (Member)members.get(n.pair()[0]);
Member p2 = (Member)members.get(n.pair()[1]);
pair.addRow(n, toPos(n.position()), p1.toString(), n.score(),
p2.toString());
}
}
Message 2 in thread
David Naylor wrote:
> Hi,
>
> Recently I have implimented a custom widget that allows multiple QTableViews
> to be included and managed as a single widget. The tables are split up into
> separate "sections" and items can be added to each section. You can select
> the width of the columns, give them headers and set wether the content can be
> edited.
>
> In order to achieve some of the functionality I have extended
> QAbstractItemModel and QItemDelegate.
>
> The code needs a lot of cleaning up and some classes should probably be
> merged. This could serve as a reference for anyone looking for an example on
> how to extend the Model/View system Qt uses (and probably a reference on how
> not to code GUI components)
>
> I am having one problem. With my current implementation of it I reload all
> the data into the Widget if some info has changed. For longer lengths of
> lists, this incurse a noticeable delay. setUpdatesEnabled doesn't appear to
> help. Any advice will be most welcome.
>
> I hope this helps, somehow
Hi David,
You haven't submitted all the files required to run this, (The package
data.Database is missing for instance) so I won't be able to run and
verify this, but in general it is significantly more costly to reset and
regenerate the tables than to update their existing contents. After you
have updated the data in the model you can emit the signal dataChanged()
http://doc.trolltech.com/4.2/qabstractitemmodel.html#dataChanged
passing it the range that has changed.
In addition to that, you can speed up inserts by using the functions:
http://doc.trolltech.com/4.2/qabstractitemmodel.html#beginInsertRows
http://doc.trolltech.com/4.2/qabstractitemmodel.html#endInsertRows
and similar for columns.
I hope this helps,
Gunnar