2012-01-11 56 views
0
QWidget* EditDelegate::createEditor(
    QWidget* parent, 
    const QStyleOptionViewItem& option, 
    const QModelIndex& index) const 
{ 
    QLineEdit* editor = NULL; 
    if(index.isValid()) 
    { 
    editor->resize(50,1000); //this can not work in win7 
    } 
    return editor; 
} 

EditDelegate是QItemDelegate的子类
你们认为这个问题是什么?如何在QLineEdit被用作编辑器时调整其大小?

+0

为什么你想调整它的大小?通常Qt会根据正在使用的视图来处理所有这些。 – Chris 2012-01-11 15:30:16

+0

我可以问你为什么试图将编辑器设置为1000像素高? – Karlson 2012-01-11 16:40:48

+0

只是我的错误 – 2012-01-12 03:44:18

回答

0

声明后QLineEdit指针,你需要创建一个类的实例

if(index->isValid()) { 
    editor = new QLineEdit(); 
    editor->resize(50, 1000); 
} 
+0

感谢所有人!我已经解决了这个问题。在QAbstractItemView中,有一个系统函数“indexWidget(...)”。哈哈,你知道我可以这样做:QWidget * editor = indexWidget(m_indexCurrent); QLineEdit * eee = qobject_cast (编辑); eee->“设定你喜欢的” – 2012-01-12 03:38:21

相关问题