How to creat a different height editer from it’s item In a QItemDelegate?



  • i am work on creat a SlippingItemView view by delegate.

    The slipping UI like:
    @


    item1


    |item2 editer |
    |(different height) |


    item3 <--this be covered
    ...


    @

    QItemDelegate show editer on item clicked , QItemDelegate::paint() reimplemented to draw the item , QItemDelegate::creatEditer() reimplemented to show a different height editer.

    It is easy to creat a different height editer by reimplemented QItemDelegate::updateEditorGeometry() , but the item sizehint will not change . Problem is editer will cover the sibling item (for example: item3).

    Question : Is there any way to update item sizehint to it's editer , and resume normal height when editer closed?



  • You want to reimplement the "QItemDelegate::sizeHint()":http://doc.qt.nokia.com/4.6/qitemdelegate.html#sizeHint function to return a different size if the item is being edited. You probably have to keep track of which items are being edited and make sure you update the layout of the items in the view when you update their sizes. You probably want to have a look at the "QAbstractItemView":http://doc.qt.nokia.com/4.6/qabstractitemview.html. Happy Hacking! :)



  • I fear it may not turn out to be easy. For instance QTableView does not listen at all to the size hint, and QListView only uses changes in the size hint if QListView::isWrapping is true. That does not mean that views, especially QListView, do not query for the size hint. They do, but they don't seem to use the result.

    I tried to use the QAbstractItemDelegate::sizeHintChanged signal to let the view know about a needed re-layout, but in my tests (by reimplementing QObject::connectNotify in the delegate), I could not see that signal actually being connected to by the views.

    Sorry to give you such negative experiences only, but I don't want you to get your hopes up too high. It me, it seems that the item views still lack a lot of optimization, documentation and polish.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.