PDA

View Full Version : Qt trying to render QTextEdit in itemdelegate , but can’t see it



umen
11th January 2012, 13:05
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 (http://programmingexamples.net/wiki/Qt/Delegates/ComboBoxDelegate) ref )
what do i do wrong here ? dont i need to point it somewhere ?


const qreal PrettyItemDelegate::THUMB_HEIGHT = 50.0;
const qreal PrettyItemDelegate::THUMB_WIDTH = 50.0;
const qreal PrettyItemDelegate::PADDING = 10.0;
const qreal PrettyItemDelegate::ITEM_HEIGHT = THUMB_HEIGHT+20;
const qreal PrettyItemDelegate::ITEM_WIDTH = THUMB_WIDTH+20;


PrettyItemDelegate::PrettyItemDelegate(QObject* parent)
: QStyledItemDelegate(parent), downloadInfo(true) {
boldFont.setBold(true);
smallerBoldFont = FontUtils::smallBold();
smallerFont = FontUtils::small();


}


QWidget *PrettyItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &/* index */) const
{
QTextEdit *editor = new QTextEdit(parent);
editor->setGeometry(QRect(40, 30, 401, 31));
editor->setLayoutDirection(Qt::LeftToRight);
//editor->setAutoFillBackground(false);
//editor->setStyleSheet(QString::fromUtf8("background-color: transparent;;"));
editor->setLocale(QLocale(QLocale::English, QLocale::UnitedStates));
editor->setFrameShape(QFrame::WinPanel);
// editor->setFrameShadow(QFrame::Plain);
editor->setLineWidth(2);
editor->setReadOnly(true);
editor->setText("This is text test!!1");

return editor;
}

void PrettyItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
QTextEdit * textEdit = static_cast<QTextEdit*>(editor);
//int value = index.model()->data(index, Qt::EditRole).toUInt();
// do somthing with the widgets
}

void PrettyItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
QTextEdit * textEdit = static_cast<QTextEdit*>(editor);
//model->setData(index, comboBox->currentIndex(), Qt::EditRole);
}

void PrettyItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}



PrettyItemDelegate::~PrettyItemDelegate() { }

QSize PrettyItemDelegate::sizeHint( const QStyleOptionViewItem& /*option*/,
const QModelIndex& /*index*/ ) const
{
return QSize( 256, THUMB_HEIGHT+20.0);
}

void PrettyItemDelegate::paint( QPainter* painter,
const QStyleOptionViewItem& option, const QModelIndex& index ) const {

int itemType = index.data(ItemTypeRole).toInt();
if (itemType == ItemTypeVideo) {
QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter );
paintBody( painter, option, index );
} else
QStyledItemDelegate::paint( painter, option, index );

}

void PrettyItemDelegate::paintBody( QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index ) const {

painter->save();
painter->translate( option.rect.topLeft() );


QRectF line(0, 0, option.rect.width(), option.rect.height());

if (downloadInfo) line.setWidth(line.width());
painter->setClipRect(line);
// get the video metadata
const StreamItemPointer pStreamItemPointer = index.data( VideoRole ).value<StreamItemPointer>();
const StreamItem *pStreamItem = pStreamItemPointer.data();

// thumb
if (!pStreamItem->thumbnail().isNull()) {
painter->drawImage(QRect(0, 0, THUMB_WIDTH, THUMB_HEIGHT), pStreamItem->thumbnail());
}
// media thumb
if(!pStreamItem->Mediathumbnail().isNull())
{
painter->drawImage(QRect(THUMB_WIDTH+10, 0, THUMB_WIDTH, THUMB_HEIGHT), pStreamItem->Mediathumbnail());
}
//save state
painter->save();
painter->restore();
// separator button line on each item
painter->setClipping(false);
painter->setPen(option.palette.color(QPalette::Midlight));
painter->drawLine(0, ITEM_HEIGHT-1, option.rect.width(), ITEM_HEIGHT-1);


painter->restore();



}

wysota
11th January 2012, 13:10
but in the end I can see the QTextEdit
So what's wrong with that? You'd like not to see it?