Results 1 to 2 of 2

Thread: Qt trying to render QTextEdit in itemdelegate , but can’t see it

  1. #1
    Join Date
    May 2009
    Posts
    83

    Default Qt trying to render QTextEdit in itemdelegate , but can’t see it

    trying to render QTextEditin item delegate , but can’t see it hi I have item deleget that I use as item in ListView . I try to set QTextEditin it , but I can’t seam to set it right , it compiles fine
    but in the end I can't see the QTextEdit
    here is my code ( taken from here ref )
    what do i do wrong here ? dont i need to point it somewhere ?

    Qt Code:
    1. const qreal PrettyItemDelegate::THUMB_HEIGHT = 50.0;
    2. const qreal PrettyItemDelegate::THUMB_WIDTH = 50.0;
    3. const qreal PrettyItemDelegate::PADDING = 10.0;
    4. const qreal PrettyItemDelegate::ITEM_HEIGHT = THUMB_HEIGHT+20;
    5. const qreal PrettyItemDelegate::ITEM_WIDTH = THUMB_WIDTH+20;
    6.  
    7.  
    8. PrettyItemDelegate::PrettyItemDelegate(QObject* parent)
    9. : QStyledItemDelegate(parent), downloadInfo(true) {
    10. boldFont.setBold(true);
    11. smallerBoldFont = FontUtils::smallBold();
    12. smallerFont = FontUtils::small();
    13.  
    14.  
    15. }
    16.  
    17.  
    18. QWidget *PrettyItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &/* index */) const
    19. {
    20. QTextEdit *editor = new QTextEdit(parent);
    21. editor->setGeometry(QRect(40, 30, 401, 31));
    22. editor->setLayoutDirection(Qt::LeftToRight);
    23. //editor->setAutoFillBackground(false);
    24. //editor->setStyleSheet(QString::fromUtf8("background-color: transparent;;"));
    25. editor->setLocale(QLocale(QLocale::English, QLocale::UnitedStates));
    26. editor->setFrameShape(QFrame::WinPanel);
    27. // editor->setFrameShadow(QFrame::Plain);
    28. editor->setLineWidth(2);
    29. editor->setReadOnly(true);
    30. editor->setText("This is text test!!1");
    31.  
    32. return editor;
    33. }
    34.  
    35. void PrettyItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
    36. {
    37. QTextEdit * textEdit = static_cast<QTextEdit*>(editor);
    38. //int value = index.model()->data(index, Qt::EditRole).toUInt();
    39. // do somthing with the widgets
    40. }
    41.  
    42. void PrettyItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
    43. {
    44. QTextEdit * textEdit = static_cast<QTextEdit*>(editor);
    45. //model->setData(index, comboBox->currentIndex(), Qt::EditRole);
    46. }
    47.  
    48. void PrettyItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
    49. {
    50. editor->setGeometry(option.rect);
    51. }
    52.  
    53.  
    54.  
    55. PrettyItemDelegate::~PrettyItemDelegate() { }
    56.  
    57. QSize PrettyItemDelegate::sizeHint( const QStyleOptionViewItem& /*option*/,
    58. const QModelIndex& /*index*/ ) const
    59. {
    60. return QSize( 256, THUMB_HEIGHT+20.0);
    61. }
    62.  
    63. void PrettyItemDelegate::paint( QPainter* painter,
    64. const QStyleOptionViewItem& option, const QModelIndex& index ) const {
    65.  
    66. int itemType = index.data(ItemTypeRole).toInt();
    67. if (itemType == ItemTypeVideo) {
    68. QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter );
    69. paintBody( painter, option, index );
    70. } else
    71. QStyledItemDelegate::paint( painter, option, index );
    72.  
    73. }
    74.  
    75. void PrettyItemDelegate::paintBody( QPainter* painter,
    76. const QStyleOptionViewItem& option,
    77. const QModelIndex& index ) const {
    78.  
    79. painter->save();
    80. painter->translate( option.rect.topLeft() );
    81.  
    82.  
    83. QRectF line(0, 0, option.rect.width(), option.rect.height());
    84.  
    85. if (downloadInfo) line.setWidth(line.width());
    86. painter->setClipRect(line);
    87. // get the video metadata
    88. const StreamItemPointer pStreamItemPointer = index.data( VideoRole ).value<StreamItemPointer>();
    89. const StreamItem *pStreamItem = pStreamItemPointer.data();
    90.  
    91. // thumb
    92. if (!pStreamItem->thumbnail().isNull()) {
    93. painter->drawImage(QRect(0, 0, THUMB_WIDTH, THUMB_HEIGHT), pStreamItem->thumbnail());
    94. }
    95. // media thumb
    96. if(!pStreamItem->Mediathumbnail().isNull())
    97. {
    98. painter->drawImage(QRect(THUMB_WIDTH+10, 0, THUMB_WIDTH, THUMB_HEIGHT), pStreamItem->Mediathumbnail());
    99. }
    100. //save state
    101. painter->save();
    102. painter->restore();
    103. // separator button line on each item
    104. painter->setClipping(false);
    105. painter->setPen(option.palette.color(QPalette::Midlight));
    106. painter->drawLine(0, ITEM_HEIGHT-1, option.rect.width(), ITEM_HEIGHT-1);
    107.  
    108.  
    109. painter->restore();
    110.  
    111.  
    112.  
    113. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by umen; 11th January 2012 at 13:26.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt trying to render QTextEdit in itemdelegate , but can’t see it

    Quote Originally Posted by umen View Post
    but in the end I can see the QTextEdit
    So what's wrong with that? You'd like not to see it?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QGLWidget render or QGraphicsView with GL viewport render
    By QTInfinity in forum Qt Programming
    Replies: 2
    Last Post: 28th November 2011, 11:34
  2. Replies: 0
    Last Post: 11th July 2011, 09:31
  3. Replies: 0
    Last Post: 21st May 2011, 21:59
  4. Can´t use opengl after upgrade. Probably a linking problem?
    By roband915 in forum General Programming
    Replies: 1
    Last Post: 9th February 2011, 23:20

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.