[Qt-interest] ***SPAM*** How to set a custom widget to fill a QListItem rect
Ramesh
ramesh.bs at robosoftin.com
Thu Mar 18 05:37:04 CET 2010
I suggest you to see this,
Hope it helps
http://lists.trolltech.com/qt4-preview-feedback/2008-04/thread00017-0.html
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of yanqzhi at gmail.com
Sent: Thursday, March 18, 2010 7:26 AM
To: qt-interest at trolltech.com
Subject: ***SPAM*** [Qt-interest] How to set a custom widget to fill a
QListItem rect
I have a subclass of QItemDelegate. In the function paint() I want to fill
option.rect with custom widget
but the posiont of the cutom widget is incorrect.
code as bellow:
main()
{
QApplication app(argc, argv);
QTableWidget *tableWidget = new QTableWidget(4, 1);
tableWidget->setItemDelegate(new SpinBoxDelegate);
for (int i=0; i<3; i++)
{
QTableWidgetItem *item = new QTableWidgetItem();
CustomWidget *widget = new CustomWidget(/*tableWidget*/);
item->setData(i, qVariantFromValue(widget) );
tableWidget->setItem(i, 0, item);
}
tableWidget->show();
return app.exec();
}
void CutomDelegate::paint(QPainter *painter, const QStyleOptionViewItem
&option,
const QModelIndex &index) const
{
if (qVariantCanConvert<CustomWidget *>(index.data()))
{
CustomWidget * widget = qVariantValue<CustomWidget *>(index.data());
widget->setGeometry(option.rect);
qDebug()<<option.rect.left() << option.rect.top() <<option.rect.right() <<
option.rect.bottom();
} else
{
QItemDelegate::paint(painter, option, index);
}
}
In main() if I set tableWidget as customWidget's parentWidget ,the custom
widget can be seen;
If no, the custom widget can't be seen;
How can I map the option.rect to tableWidget in the function paint()?
Thanks.
yanqzhi at gmail.com
2010-03-18
-----------------------------------------------
Robosoft Technologies - Come home to Technology
Disclaimer: This email may contain confidential material. If you were not an intended recipient, please notify the sender and delete all copies. Emails to and from our network may be logged and monitored. This email and its attachments are scanned for virus by our scanners and are believed to be safe. However, no warranty is given that this email is free of malicious content or virus.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100318/062709ff/attachment.html
More information about the Qt-interest-old
mailing list