PDA

View Full Version : QTextEdit does not show!!!!



MarkoSan
9th January 2008, 15:58
Hi again to all!

I have a code:
void CMerchandizeBrowser::paintEvent(QPaintEvent* event)
{
Q_UNUSED(event);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, false);
painter.drawImage(QPoint(0,0), d->buffer);

// shows merchandize info: name, price, descriptions
painter.setPen(Qt::white); // sets white pen's color
painter.setBrush(Qt::NoBrush); // sets brush
//p.drawRect(merchandizeDescriptionRect);
painter.setFont(QFont("Arial", 12)); // sets test font
QFontMetrics fm(painter.font()); // sets up font metrcis
QRectF computedRec(merchandizeDescriptionRect);
/*
painter.drawText(computedRec, Qt::AlignLeft, getMerchandizeName(m_ImagesList.at(m_iSelected).te xt(strKeyImagePathName)));
*/
painter.drawText(computedRec, Qt::AlignLeft, getMerchandizeName(d->slideImages.at(currentSlide()).text(strKeyImagePat hName)));
// appends "euro" sing at the end of the price
QString priceString(getMerchandizePrice(d->slideImages.at(currentSlide()).text(strKeyImagePat hName)));
priceString=priceString.append(" EUR");
painter.drawText(computedRec, Qt::AlignRight, priceString);
// shows merchandize description
QTextEdit merchandizeDescription(getMerchandizeDescription(( qint16)currentSlide()), this); // new instance of qtextedit
merchandizeDescription.show(); // shows constucted text
}And QTextEdit is not shown? Can someone help me out, please?

jacek
9th January 2008, 16:13
You create QTextEdit on the stack and it immediately goes out of scope, so you don't have a chance to see it. Also paintEvent() isn't the best place to create widgets.