Results 1 to 6 of 6

Thread: Using Designer to implement a QItemDelegate

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2010
    Posts
    20
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Using Designer to implement a QItemDelegate

    Sorry, I'm currently try to understand what you meand. In addition I'll try to show what I'm trying to do.
    My idea (I don't know if it is the best) is to use the render method of the widget prom the delegate:aint
    Becuse the widget has to show 3 labels and an image in principle, and in the future could be change and I think that if I use the designer and someting change, I won't have to change the code.

    The problem is that when I try to render the widget, I can't indicate where it should be draw
    This is an example:

    Qt Code:
    1. void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
    2. {
    3. ItemWidget item;
    4.  
    5. item.setGeometry(option.rect);
    6.  
    7. item.render(painter);
    8. }
    To copy to clipboard, switch view to plain text mode 

    Regards

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: Using Designer to implement a QItemDelegate

    I guess you will need to calculate that yourself.
    Using a ItemWidget inside paint is quite heavy. You are literally creating and destroying a widget on every paint event !!

    Proper way would be, calculate the rects of text and image you want to draw and simply draw them. dont use any widget.render() .
    If more curious, you can dig into code of QItemDelegate and see how it renders the item. You will get the idea.

  3. #3
    Join Date
    Jul 2010
    Posts
    53
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default Re: Using Designer to implement a QItemDelegate

    look at my example:

    Qt Code:
    1. QLabel renderer;
    2. renderer.setObjectName("renderer");
    3. renderer.setStyleSheet(getStyleSheet(index));
    4. renderer.setText(makeDisplayString(index));
    5. renderer.resize(option.rect.size());
    6. painter->save();
    7. painter->translate(option.rect.topLeft());
    8. renderer.render(painter);
    9. painter->restore();
    To copy to clipboard, switch view to plain text mode 

    here i render label with my style sheet.

    you must draw here:

    Qt Code:
    1. option.rect.topLeft()
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Aug 2010
    Posts
    20
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Using Designer to implement a QItemDelegate

    And what about creating only one widget which is a member of the delegate to avoid the creation of the object.

    And still using the render, or is any other thing to take care about that?

    Rigth now, the item is not so complicated I'll try to make it by hand.

Similar Threads

  1. How does Qt implement layers?
    By FinderCheng in forum Qt Programming
    Replies: 1
    Last Post: 16th October 2009, 13:12
  2. how to implement this widget
    By pencilren in forum Qt Programming
    Replies: 2
    Last Post: 15th June 2007, 11:10
  3. What's the best way to implement a MainWindow
    By darkadept in forum Qt Programming
    Replies: 5
    Last Post: 5th February 2007, 17:46
  4. how to implement it ?
    By qtopiahooo in forum Qt Programming
    Replies: 3
    Last Post: 25th October 2006, 17:01
  5. Replies: 3
    Last Post: 12th May 2006, 19:31

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
  •  
Qt is a trademark of The Qt Company.