Results 1 to 6 of 6

Thread: How to center an item editor created by a custom item delegate?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to center an item editor created by a custom item delegate?

    i tried to change updateEditorGeometry().
    Qt Code:
    1. void MyDelegate::updateEditorGeometry( QWidget * editor, const QStyleOptionViewItem option, const QModelIndex & index ) const
    2. {
    3. QRect rect = option.rect;
    4.  
    5. if (index.column() == m_VisibilityColumnIndex)
    6. {
    7. rect.setX(rect.x() + 10);
    8. }
    9.  
    10. editor->setGeometry(rect);
    11. }
    To copy to clipboard, switch view to plain text mode 
    but obviously the method never gets called (i set a breakpoint there). so what can i do?

  2. #2
    Join Date
    Mar 2009
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to center an item editor created by a custom item delegate?

    btw: in my code example i just tried to move the checkbox 10 pixels to the right (instead of centering it)-> just for demonstration

  3. #3
    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: How to center an item editor created by a custom item delegate?

    Does ur createEditor function gets called ?
    If not check if the item is set as editable or not. updateEditorGeometry must be called if the editor is created...

  4. #4
    Join Date
    Aug 2009
    Posts
    1
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to center an item editor created by a custom item delegate?

    The only way i found is to set a QMyStyle to the QTableView

    m_pMyTableView->setStyle(new QMyStyle());

    In QMyStyle you should overload subElementRect(...) Method as follow :

    QRect QMyStyle::subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *widget) const
    {

    //die CheckBox mittig ausrichten
    if (sr == QStyle::SE_ItemViewItemCheckIndicator || sr == QStyle::SE_CheckBoxIndicator)
    {
    QRect r = QWindowsVistaStyle::subElementRect(sr, opt, widget);
    int center = opt->rect.center().x();
    return QRect(QPoint(center - r.width() / 2, r.y()), QPoint(center + r.width() / 2, r.bottom()));
    }

    return QWindowsVistaStyle::subElementRect(sr, opt, widget);
    }


    regards,
    Max

Similar Threads

  1. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37
  2. QMovie from inside a custom item delegate
    By Crazy_Hopper in forum Qt Programming
    Replies: 3
    Last Post: 7th May 2008, 15:18

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.