[Qt-interest] Model/View programming: QTableView with custom item delegate or custom view class?
Robert Hairgrove
evorgriahr at hispeed.ch
Tue Jan 19 20:49:22 CET 2010
KC Jones wrote:
> On Mon, Jan 18, 2010 at 1:16 PM, Robert Hairgrove <evorgriahr at hispeed.ch> wrote:
>> I need to create a custom view for editing teachers' schedules which
>> have lessons of varying length and am not quite sure of the best way of
>> going about it. I already implemented one version using a QTableView,
>> but this works only under the assumption that all lessons have lengths
>> that are some integer multiple of the smallest time slot. Lessons are
>> represented by colored rectangles on a white background. I would like to
>> offer the user more flexibility -- lessons should be able to cross item
>> borders if necessary, and lessons can be of any duration as specified by
>> the user.
>>
>> Of course, it is lots of work to inherit directly from QAbstractItemView
>> and have to deal with all the scrolling, etc. I took a look at the Pie
>> Chart example, and it didn't look too intimidating, although it is still
>> a lot of work to implement the paintEvent() function, for example. Can I
>> do it with a QTableView and a custom item delegate instead?
>>
> Shooting from the hip: I would consider implementing a delegate that
> represents a whole day, and using the flexibility of the paint and
> edit methods to tackle the problem of custom lesson scheduling.
>
> Are the days laid out horizontally or vertically? If they are
> horizontal, you could use a QListView, or more likely a QTreeView if
> there are columns other than the day plan. If they are vertical,
> QTableView or a custom QAbstractItemView would be needed.
>
> But beware: your delegate will really want to be a composition of
> other widgets and this is a problem I have run into and found Qt to
> come up short. There are some KDE widgets that fill this gap.
> Someone here recommended them to me and they do look quite useful. In
> my case I decided that my models were simple enough that I did not
> need to use Qt model/view classes and I am now stacking an array of my
> composite widgets into a QScollArea. That's working pretty well.
>
> In any case, sounds like a lot of work. Not sure how much of the
> QTableView implementation will migrate into the new scheme.
Thanks for your thoughts! There is also the "Pixelator" example which
has given me some food for thought. The Qt object model is flexible
enough that eventually, I think a solution will fall in place.
More information about the Qt-interest-old
mailing list