[Qt-interest] item delegate issue

Andre Somers andre at familiesomers.nl
Mon Jul 12 09:22:26 CEST 2010


On 12-7-2010 1:04, Sajjad wrote:
> Hello forum,
>
> I have several labels placed in the horizontal layout. If i 
> double-click some of the labels the spin box widgets should show up in 
> the place of labels and provide me the editing facilities. To get this 
> done i have gone through the spinbox delegate example and in the 
> example they have implemented the spin box inside the  table model and 
> view. They set the item delegate as follows:
>
>     SpinBoxDelegate delegate;
>     tableView.setItemDelegate(&delegate);
>
>
> I want to get it inside the QLabel and it does not have any function 
> like setItemDelegate();
>
>
>
> Any hint?
>
>
Delegates are a piece of the Item/View framework in Qt. Labels have 
nothing to with that, so you can not apply a delegate on a label. The 
only "normal" widget that you might use a delegate on is the QComboBox 
(on the list part). For the rest, they work only on Q*View (like 
QListView) and their *Widget pendants (QListWidget and the likes).

I think you should look into using a QWidgetStack on your form, with a 
QLabel on one page of the stack, and a QSpinBox on the other. Then, you 
need to catch the double click event on the label. There are two ways to 
do that:
1) subclass QLabel and reimplement mouseDoubleClickEvent() and emit a 
custom signal that you use to trigger the switch to the page with the 
QSpinBox.
2) use an event filter from your form class to catch the double click 
event, and do your handling from there. I think I would prefer the 
second option in this case, unless you think you need QLabels that emit 
double clicks as signals more often.

Good luck!

André

-- 
Nokia Certified Qt Developer.
Interested in Qt related job offers or freelance Qt consulting work.




More information about the Qt-interest-old mailing list