PDA

View Full Version : Custom controls when QTreeWidgetItem edited.



kubas
3rd September 2009, 16:23
Hey,
i dont have great expirience with qt. What i want to do is to change the
control (QLineEdit) if i double click on item in qtreewidget.
How to make this. I'm not looking for entire solution, just for
guidlines how to "bite" it where to search, what to exatly read.

I'd be grateful for any inforamtion in this case :)

Best regards,
Kubas

faldzip
3rd September 2009, 19:37
take a look at Spin Box Delegate example. You can find it in Qt Examples & Demos -> Item Views, or on the web here (http://doc.trolltech.com/4.5/itemviews-spinboxdelegate.html)

aamer4yu
4th September 2009, 06:40
With QTreeWidget you will only need to set proper flags on the tree widget item.
QTreeWidgetItem::setFlags
You could use it like -

pItem->setFlags(pItem->flags() | Qt::ItemIsEditable);
Then when you press F2 , Qt will handle the editing mode.

kubas
4th September 2009, 11:27
Thanks for help, but i got another issue,
i followed the spinbox delegate example, and i did just as written there
i tried to set as editor QTimeEdit, but when i double click the item
it opens a new small window with the QTimeEdit if i close it data are
updated in gui. I'm using qt-jambi, is it bug ? Additionally when i close my app
i get:
QtJambi: Exception pending in native code in file '..\cpp\com_trolltech_qt_gui\qtjambishell_QItemDel egate.cpp':476

Is there any other way to do this ?
I found setData methid for each item, and there i can set which control
should be used for editing, but i cannot place there QTimeEdit, i can only
use there QTime but it doesnt allow to set display format and its always
HH:mm:ss and i want only HH:mm.
Any ideas ?

Thank you in advance :)
Kubas