Moin Moin,
habe jetzt schon längere Zeit im Forum und Internetz rumgesucht, leider ohne Ergebnis. Darum hier meine Frage:
Ich möchte eine Combobox und ein TextEdit Widget in einem ItemDelegate unterbringen. Mit einem Widget klappt alles, aber bei zweien wird nichts mehr, bzw. mit setAutofillBackground nur mist angezeigt.
QWidget *DatenDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,
const QModelIndex &/* index */) const
{
QWidget *editor = new QWidget(parent);
QHBoxLayout *layout = new QHBoxLayout();
QComboBox *combo = new QComboBox(editor);
QDirIterator it(":/subitems");
while (it.hasNext()) {
combo->addItem(QIcon(it.next()), QString());
}
QTextEdit *edit = new QTextEdit(editor);
layout->addWidget(combo);
layout->addWidget(edit);
editor->setLayout(layout);
editor->show();
return editor;
}
Irgenntjemand ne Idee wie man zwei oder mehr Widgets in einem ItemDelegate::createEditor-Widget unterbringt? Ich vermute es ist ein Problem mit meinem Widget-Layout ..
QWidget *DatenDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,
const QModelIndex &/* index */) const
{
QWidget *editor = new QWidget(parent);
editor->setAutoFillBackground(true);
QHBoxLayout *layout = new QHBoxLayout();
QComboBox *combo = new QComboBox(editor);
QDirIterator it(":/subitems");
while (it.hasNext()) {
combo->addItem(QIcon(it.next()), QString());
}
QLineEdit *edit = new QLineEdit(editor);
layout->addWidget(combo);
layout->addWidget(edit);
editor->setFixedSize(layout->totalMinimumSize());
layout->setMargin(0);
layout->setContentsMargins(0,0,0,0);
layout->setSizeConstraint(QLayout::SetMinimumSize);
editor->setLayout(layout);
editor->show();
return editor;
}
Die beiden Elemente werden jetzt zwar angezeigt aber nicht in der Größe des zu editierenden Elements. Ich bräuche nur die richtigen Parameter für die SizePolicy usw.
Kann mir da niemand helfen?