How to update height of QStandardItem/Delegate?
-
So i have a delegate inside a qlistview and as an editor i define my own widget "section" that is a scrollarea itself and can expand. But how can i update the size of the Delegate when the widgets size changes? Can anyone hint me the way? Thanks in advance. :)
Bugging out really wierd after closing cause no new SizeHint to delegate.
#include "modulitemdelegate.h" #include <QLineEdit> #include <QFormLayout> #include <QComboBox> #include "Section.h" modulitemDelegate::modulitemDelegate(QObject *parent) : QStyledItemDelegate{parent} {} QWidget *modulitemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { Section* section = new Section("Section " + QString::number(1), 30, true, true, false, parent); section->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); connect(section, &Section::SendSizeUpdate, this, &modulitemDelegate::ReceiveSizeUpdate); // Erstelle Layout und fülle es mit Widgets für die Section auto* formLayout1 = new QFormLayout(); QLineEdit *lineEdit1 = new QLineEdit(); QLineEdit *lineEdit2 = new QLineEdit(); QComboBox *comboBox = new QComboBox(); formLayout1->addRow("Label 1:", lineEdit1); formLayout1->addRow("Label 2:", lineEdit2); formLayout1->addRow("Combo Box:", comboBox); // Setze das Layout für die Section section->setContentLayout(*formLayout1); return section; } void modulitemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { } void modulitemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { } QSize modulitemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { // Gib den Standard-SizeHint zurück QSize s = QStyledItemDelegate::sizeHint(option, index); return s; }
Anyone can help? @JonB
-
@StudentScripter I only know of making
sizeHint()
work for the correct state. -
@SGaist Hey thanks for responding. :) What exatly do you mean with showing it outside? Isn't an delegate thought to show within one cell. Could may elaborate on what you mean and how to do it. That would be very helpful.
My goal is a list like on the right side of Godot, but with rearangable dropdown menus. The menus shown switch depending on which element is clicked.
-
When the editor is big and complex, it might be better to have it off cell.
That said, I think you might be taking the wrong approach here. The inspector on the right seems to be a full fledged widget not a delegate.
I see a combo-box at the top which is likely a selector that will trigger the selection of the current item to show. Once selected, the inspector will be loaded with the detail for this item. This could be accomplished with a QDataWidgetMapper.
-
@StudentScripter can you explain what you mean by module ?
-
@SGaist One Dropdown section with all the widgets that are into such a dropdown.
So for example modul1/dropdown1:
-4 lineedits for width, height, posx, posymodul2/dropdown2:
-checkbox for hiding elements in the scene
-lineedit for setting the name of the item ins sceneand so on you get the point. :) Have a nice weekend.
-
@StudentScripter Did you consider having a "edit mode" where you move things around ?
-
@SGaist Preferabily i would like to not have an edit mode, if possible. But whats your idea with an edit mode?
Also if not using that. Would implementing drag and drop inside they layout be the way or is there any other better methode? Thank you very much.
-
@StudentScripter with the edit mode, you can make your widgets look a bit like a dashboard where you move things around a bit like on iOS when you long press on the screen and things start wobbling. You can then move them around and once it's done you can again use them.
As for your second question, it's rather at the containing widget level that you would do that. You would move things around in the layout but it's not the layout that is responsible for the D&D part as layouts do not have a "body".
-
@SGaist Yeah i primarily meant drag and drop within the qscrollarea where the layout is located. But is this really my best option? What to keep in mind when having many widgets? Or is removing the widgets that are currently not supposed to be shown from the layout enough? Have good 1st may.
-
@StudentScripter Things to keep in mind is that if you have a QScrollArea that contains the equivalent of multiple screens worth of widgets, then it won't be nice for your users.
You should start by drawing your widgets and then think about how many are necessary, how they should be shown, etc. And if possible discuss that with people from your target audience.
-
@SGaist Thank you very much. One last questions before closing this thread:
- Does using setListWigetItem (QListWidget) make an difference in performance compared to just using the widgets inside a scrollarea or is the overhead the same?
Have a nice day! :)