كيتمديليغات مع الحاجيات المخصصة
-
26-12-2019 - |
سؤال
أواجه مشاكل مع بلدي QTableView
و QItemDelegate
الطبقات.لعمود واحد يقوم مندوبي بإنشاء مربع تحرير وسرد بسيط ويعمل كل شيء على ما يرام.لبلدي العمود 2 أحتاج إلى القطعة التي لديها اثنين من صناديق التحرير والسرد في القطعة واحدة.
لقد كتبت التعليمات البرمجية التالية في بلدي QItemDelegate
, ، لمجرد أن يكون واضحا هذا يظهر فقط رمز لبلدي العمود 2 ، واحد أن لا يعمل.لا يظهر مربع التحرير والسرد البسيط الآخر لأنه يعمل بشكل جيد:
QWidget *UserDefinedUnitsDelegate::createEditor(QWidget *parent,const QStyleOptionViewItem & option ,const QModelIndex & index ) const
{
//set up a simple widget with a layout
QWidget* pWidget = new QWidget(parent);
QHBoxLayout* hLayout = new QHBoxLayout(pWidget);
pWidget->setLayout(hLayout);
//add two combo boxes to the layout
QComboBox* comboEditor = new QComboBox(pWidget);
QComboBox* comboEditor2 = new QComboBox(pWidget);
//now add both editors to this
hLayout->addWidget(comboEditor);
hLayout->addWidget(comboEditor2);
return pWidget;
}
الآن يتم عرض هذا على ما يرام ولكن عندما أقوم بتحريره والنقر في مكان آخر ، فإنه لا يتوقف عن التحرير.يمكن لأي شخص أن يقدم أي مؤشرات?
تحرير:لذلك أنا بحاجة إلى استدعاء كونداتا() و كلوسيديتور () في مرحلة ما.يمكن لأي شخص أن يقدم مؤشرات حول مكان استدعاء هذه?
شكرا.
المحلول
يمكنك الحفاظ على القطعة محرر كعضو من الطبقة وتنبعث كونداتا عندما تغير الفهرس الحالي لأحد كومبوبوكسس.حتى تتمكن من الاتصال كيرنتينديكسشانجد (إنت) إلى فتحة وتنبعث كونداتا من هناك:
QWidget *UserDefinedUnitsDelegate::createEditor(QWidget *parent,const QStyleOptionViewItem & option ,const QModelIndex & index ) const
{
//set up a simple widget with a layout
pWidget = new QWidget(parent);
QHBoxLayout* hLayout = new QHBoxLayout(pWidget);
pWidget->setLayout(hLayout);
//add two combo boxes to the layout
QComboBox* comboEditor = new QComboBox(pWidget);
QComboBox* comboEditor2 = new QComboBox(pWidget);
connect(comboEditor,SIGNAL(currentIndexChanged(int)),this,SLOT(setData(int)));
connect(comboEditor2,SIGNAL(currentIndexChanged(int)),this,SLOT(setData(int)));
//now add both editors to this
hLayout->addWidget(comboEditor);
hLayout->addWidget(comboEditor2);
return pWidget;
}
void UserDefinedUnitsDelegate::setData(int val)
{
emit commitData(pWidget);
}