void QgsDetailedItemDelegate::paint( QPainter * thepPainter,
                                     const QStyleOptionViewItem & theOption,
                                     const QModelIndex & theIndex ) const
{
  // After painting we need to restore the painter to its original state
  thepPainter->save();
  if ( theIndex.data( Qt::UserRole ).canConvert<QgsDetailedItemData>() )
  {
    QgsDetailedItemData myData =
      theIndex.data( Qt::UserRole ).value<QgsDetailedItemData>();
    if ( myData.isRenderedAsWidget() )
    {
      paintAsWidget( thepPainter, theOption, myData );
    }
    else //render by manually painting
    {
      paintManually( thepPainter, theOption, myData );
    }
  } //can convert item data
  thepPainter->restore();
}
QSize QgsDetailedItemDelegate::sizeHint(
  const QStyleOptionViewItem & theOption,
  const QModelIndex & theIndex ) const
{
  if ( theIndex.data( Qt::UserRole ).canConvert<QgsDetailedItemData>() )
  {
    QgsDetailedItemData myData =
      theIndex.data( Qt::UserRole ).value<QgsDetailedItemData>();
    if ( myData.isRenderedAsWidget() )
    {
      return QSize( 378, mpWidget->height() );
    }
    else // fall back to hand calculated & hand drawn item
    {
      //for some reason itmes are non selectable if using rect.width() on osx and win
      return QSize( 50, height( theOption, myData ) );
      //return QSize(theOption.rect.width(), myHeight + myVerticalSpacer);
    }
  }
  else //cant convert to qgsdetaileditemdata
  {
    return QSize( 50, 50 ); //fallback
  }
}