Results 1 to 20 of 20

Thread: Delegate editor sizing problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2007
    Posts
    73
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Delegate editor sizing problem

    I have have implemented a custom delegate and model for editing all the QTableView cells in a very controlled way. When my delegates create the editor, it doesn't fill up the available space in the cell. Is there something that I need to do to make this happen?

    Thanks in advance,
    Susan

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Delegate editor sizing problem

    Reimplement the sizeHint method, and return the cell size.

  3. #3
    Join Date
    Feb 2007
    Posts
    73
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Delegate editor sizing problem

    How does the delegate find out the size of the cell? It has no direct access to the view that I know of.

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Delegate editor sizing problem

    Sorry about that... sizeHint is a wrong path.

    Try overriding QItemDelegate::updateEditorGeometry(...);
    Like this:

    Qt Code:
    1. [COLOR=#8B0000][FONT='Courier New,courier'][I][/I][/FONT][/COLOR]void MyDelegate::updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem &option, const QModelIndex &index )
    2. {
    3. editor->setGeometry( option.rect );
    4. }
    To copy to clipboard, switch view to plain text mode 

    Using option.rect should resize your editor to fit perfectly into the cell.

    Regards

  5. The following user says thank you to marcel for this useful post:

    smacchia (8th April 2007)

  6. #5
    Join Date
    Feb 2007
    Posts
    73
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Delegate editor sizing problem

    Just what I was looking for! I'll give this a try.

    --Susan

  7. #6
    Join Date
    Feb 2007
    Posts
    73
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs down Re: Delegate editor sizing problem

    Unfortunately, this method never gets called!!! I am not sure why. I have an example MVC implementation from a training class I attended and the delgates never implemented this method and the editor (spinbox or combo) was always sized correctly... Ideas?

  8. #7
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Delegate editor sizing problem

    No idea why it isn't called, but take a look at the Spin Box delegate example in the Qt Demos ( Item Views section ).

    It does something similar to what you want.

  9. #8
    Join Date
    Feb 2007
    Posts
    73
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Delegate editor sizing problem

    I think its not called because in the Qt source for QItemDelegete, it isn't virtual!! (it is supposed to be). Stepping through the Qt code for creating the delegate editor, it invokes QItemDelegate::updateEditorGeometry, not my derivation! I'll look at the example that you site, but I think this is the culprit. My example from the class is pretty straight forward too and doesn't event reimplement that method...

  10. #9
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Delegate editor sizing problem

    void QItemDelegate::updateEditorGeometry ( QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex & index ) const [virtual] Updates the editor for the item specified by index according to the style option given.
    Reimplemented from QAbstractItemDelegate.
    This is the member description from QItemDelegate. As you can see it is virtual. Also this member is public and const. Perhaps you didn't declare it as public in your class?

  11. #10
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Delegate editor sizing problem

    Actually you're right. I just took a look at QItemDelegate.h and the member is not virtual.
    But it is in QAbstractItemDelegate. Couldn't you derive your delegate from QAbstractItemDelegate instead?

  12. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Delegate editor sizing problem

    Quote Originally Posted by smacchia View Post
    I think its not called because in the Qt source for QItemDelegete, it isn't virtual!!
    It is virtual. It doesn't have to be marked as virtual in QItemDelegate definition, since it was declared as virtual in QAbstractItemDelegate.

    Quote Originally Posted by marcel View Post
    Also this member is public and const. Perhaps you didn't declare it as public in your class?
    Also make sure you didn't forget about "const". It's quite common mistake.

  13. The following user says thank you to jacek for this useful post:

    smacchia (9th April 2007)

  14. #12
    Join Date
    Feb 2007
    Posts
    73
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Delegate editor sizing problem

    Oh duh - it was the "const". Thanks! It works great now.

  15. #13
    Join Date
    Sep 2007
    Posts
    29
    Thanks
    8

    Default Re: Delegate editor sizing problem

    i got a similar problem with delegates and a QTreeView, but i'm using editing widgets that contain other widgets, eg. a QWidget containing a QLineEdit.
    first, i tried adding a layout to the container widget and adding sub-widgets to it, but the result was that the item didn't seem to be editable anymore at all (or the widget has hone somewhere / was zero-sized or whatever).
    i tried overriding the setGeometry function for my subclasses but when the delegate calls setGeometry, allways the standard QWidget function is called.
    i declared setGeometry as:
    Qt Code:
    1. virtual void setGeometry(const QRect &r)
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  2. Problem in Cut Operation
    By ankurjain in forum Qt Programming
    Replies: 4
    Last Post: 14th April 2006, 12:23
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.