在qtcn上提出这个问题,有人建议用QItemDelegate,createEditor方式
http://www.qtcn.org/bbs/read.php?tid=33532
测试代码:
#ifndef IMWIDGET_H
#define IMWIDGET_H
#include <QtGui>
class ImWidget : public QWidget
{
Q_OBJECT
public:
ImWidget(QWidget * parent = 0, Qt::WindowFlags f = 0);
void setData();
public slots:
void slotPrintf(const QString & currentText ){
qDebug() << "item = " << currentText;
}
public:
QListWidget *listWidget;
};
#endif
#include "ImWidget.h"
#include "delegate.h"
ImWidget::ImWidget(QWidget * parent, Qt::WindowFlags f )
:QWidget(parent, f){
listWidget = new QListWidget();
QHBoxLayout *layout = new QHBoxLayout();
layout->addWidget(listWidget);
setLayout(layout);
//connect(listWidget, SIGNAL(currentTextChanged( const QString &)), this, SLOT(slotPrintf(const QString &)));
}
void ImWidget::setData(){
SpinBoxDelegate *delegate = new SpinBoxDelegate(listWidget);
listWidget->setItemDelegate(delegate);
connect(delegate, SIGNAL(sglChangeText( const QString &)), this,