Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / qt / 2007-07

Problems with OwnerDraw ListWidget and friends

10 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Paul Ishenin

Hello, Items specific to the Qt widget set.

In LCL we have many item containers that can have custom draw item events.

To implement this functionality I suposed it will be enough to listen painEvent and call draw item events while traversing items.

But qt suggest anther approach for that - override QAbstractItemDelegate. We already have QComboBox_setItemDelegate, QAbstractItemView_setItemDelegate and so on. We only need our own delegate.

I dont think it is not possible to subclass QAbstractItemDelegate in pascal. So we need this thing in bindings.

We only should override 2 methods: paint and sizeHint at moment to achive needed result.

We need that paint and sizeHint methods redirect calls to our own methods. We can for example use constructor and pass that methods as arguments or we can use getters and setters.

For example:

Delegate := QPascalItemDelegate_create(@PaintHook, @SizeHintHook);
QComboBox_setItemDelegate(Delegate);
...

Den, what do you think. Is it possible?

Best regards, Paul Ishenin.
Paul Ishenin
to Paul Ishenin
Paul Ishenin wrote 29 lines
Hello, Items specific to the Qt widget set. In LCL we have many item containers that can have custom draw item events. To implement this functionality I suposed it will be enough to listen painEvent and call draw item events while traversing items. But qt suggest anther approach for that - override QAbstractItemDelegate. We already have QComboBox_setItemDelegate, QAbstractItemView_setItemDelegate and so on. We only need our own delegate. I dont think it is not possible to subclass QAbstractItemDelegate in pascal. So we need this thing in bindings. We only should override 2 methods: paint and sizeHint at moment to achive needed result. We need that paint and sizeHint methods redirect calls to our own methods. We can for example use constructor and pass that methods as arguments or we can use getters and setters. For example: Delegate := QPascalItemDelegate_create(@PaintHook, @SizeHintHook); QComboBox_setItemDelegate(Delegate); ... Den, what do you think. Is it possible?

It will be even better to override QItemDelegate instead of QAbstractItemDelegate. Sice QItemDelegate already has default implementation we can turn it on if we will not process that painting ourself.

Best regards,
Paul Ishenin.

zeljko
to Paul Ishenin
Paul Ishenin wrote
It will be even better to override QItemDelegate instead of QAbstractItemDelegate. Sice QItemDelegate already has default implementation we can turn it on if we will not process that painting ourself.

I'll prefer both in bindings.

Den Jean
to Paul Ishenin: Hello, Items specific to the Qt widget set. In LCL we have many item containers that can…
Paul Ishenin wrote
In LCL we have many item containers that can have custom draw item events.

I see the binding for LCL needs, not for pascal Qt programming. For this indeed method overriding is lacking. For LCL it is normally not needed, almost everything can be overriden via the eventfilter (proof is CLX).

So everything needed is present.

QAbstractItemDelegate is just more abstraction, they needed something to sell Qt 4. It is not present in Qt 3. The commercial nature of Qt makes that over time it is moving from perfect lean design to big monster due to the stupid need to have something new in every release. Please do not use something so advanced in a widgetset interface.

Catching paint events and other events via event filters, void the need to derive the class. It is just catching signals. Qt is build for that. But for method overriding, you need to subclass.

Please review your request or elaborate further.

Anyhow creating a framework for method overriding is a lot of work, weeks, so perhaps it is better spent on something else.

I would prefer that the simple things work first, before we work on custom drawn combo box items. But we can also come back on this later.

Radio buttons do not work yet, even with the QT_HIDDEN_BUTTON_WORKAROUND. The horizontal positions are not correct, nor the tab order (key up/down). Could we work on such things first. I tried to read the code, but do not even find were the positions are set.

kind regards,

Den Jean

Unknown author
to Den Jean

Quoting Den Jean :

Show quoted text 7 lines
On Friday 20 July 2007 05:54:09 Paul Ishenin wrote: > In LCL we have many item containers that can have custom draw item events. Radio buttons do not work yet, even with the QT_HIDDEN_BUTTON_WORKAROUND. The horizontal positions are not correct, nor the tab order (key up/down). Could we work on such things first. I tried to read the code, but do not even find were the positions are set.

I agree with you about QAbstractItemDelegate, and about QT_HIDDEN_BUTTON_WORKAROUND, my svn copy already contains some changes which fixes a lot of geometry & positioning problems, but we have to discuss about it.
eg. I don't get LCL's diff between GetClientRect() and GetClientBounds(). First one should return ClientRect() and second one BoundsRect() similar as in Delphi. Isn't it ? or I'm wrong ...
Anyway , my wiki page contains things which I changed today on the beach ;), and will be commited when you try it on your distro and when Paul try it on his WinXP. I've already tested changes on WinXP , FC3, FC4 & FC7 and it looks ok.
Pls. write me which screen resolutions and dpi settings you use on Linux. I'm using 1280x1024 96x96 dpi (WinXP & Linux).

here is my wiki link:
http://wiki.lazarus.freepascal.org/User:Zeljan

Den Jean
to Unknown author
Anyway , my wiki page contains things which I changed today on the beach ;), and will be commited when you try it on your distro and when

how test something we do not have ???
commit please

Paul try it on his WinXP. I've already tested changes on WinXP , FC3, FC4 & FC7 and it looks ok. Pls. write me which screen resolutions and dpi settings you use on

1920x1200 and 1680x1050
90x89 DPI

Paul Ishenin
to Den Jean: I see the binding for LCL needs, not for pascal Qt programming. For this indeed method…
Den Jean wrote 6 lines
On Friday 20 July 2007 05:54:09 Paul Ishenin wrote: > In LCL we have many item containers that can have custom draw item events. I see the binding for LCL needs, not for pascal Qt programming. For this indeed method overriding is lacking. For LCL it is normally not needed, almost everything can be overriden via the eventfilter (proof is CLX).

Ok, I tell me what is:
QClxListItem_measure_Event, QClxListBoxHooks_hook_measure, QClxListItem_paint_Event, QClxListBoxHooks_hook_paint

So everything needed is present.

No. As I understand borland used same approach. They subclassed QAbstractItemDelegate or QItemDelegate and overrided sizeHint and paint. They also provided that two methods: QClxListBoxHooks_hook_measure and QClxListBoxHooks_hook_paint.

We need something about the same. We need to subclass QItemDelegate and provide 2 our own event. Measure event will be passed on QItemDelegate.sizeHint call and paint event on paint.

If that events are not processed then default behaviour should be used.

Anyhow creating a framework for method overriding is a lot of work, weeks, so perhaps it is better spent on something else.

No we doesnot need such framework. We need only one special class in bindings (written on c++) and need 2 special hook install methods. No more no less.

Show quoted text 8 lines
I would prefer that the simple things work first, before we work on custom drawn combo box items. But we can also come back on this later. Radio buttons do not work yet, even with the QT_HIDDEN_BUTTON_WORKAROUND. The horizontal positions are not correct, nor the tab order (key up/down). Could we work on such things first. I tried to read the code, but do not even find were the positions are set.

hope it is fixed now :)

Best regards,
Paul Ishenin.

Den Jean
to Paul Ishenin
Paul Ishenin wrote
We need something about the same. We need to subclass QItemDelegate and provide 2 our own event. Measure event will be passed on QItemDelegate.sizeHint call and paint event on paint.

I will look into it.

regards,

Den Jean

Павел Ишенин
to Den Jean
Den Jean wrote 9 lines
On Friday 27 July 2007 10:37:45 Paul Ishenin wrote: > We need something about the same. We need to subclass QItemDelegate and > provide 2 our own event. Measure event will be passed on > QItemDelegate.sizeHint call and paint event on paint. > I will look into it.

Big thanks.

Best regards,
Paul Ishenin.

Den Jean
to Paul Ishenin: Ok, I tell me what is: QClxListItem_measure_Event, QClxListBoxHooks_hook_measure,…
Paul Ishenin wrote
We need something about the same. We need to subclass QItemDelegate and provide 2 our own event. Measure event will be passed on QItemDelegate.sizeHint call and paint event on paint.

for Zeljko too:

i just read this in
src/gui/itemviews/qitemdelegate.h.
The HMargin may be of interest.

/*!
Returns the size needed by the delegate to display the item specified by \a index, taking into account the style information provided by \a option.

When reimplementing this function, note that in case of text items, QItemDelegate adds a margin (i.e. 2 *
QStyle::PM_FocusFrameHMargin) to the length of the text. */

QSize QItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const