Custom editor for a delegate
-
Hi.
Im trying to make a custom editor for a delegate in a tableview. I tried to subclass QWidget and use it as a editor. Problem is, when i start it standalone, if works. If i pass it in the delegates createEditor and setEditorData, its blinks fast and goes right to setModelData without waiting for input. and its shown as a regulan window, but i want it without the close, minimize and fullscreen buttons and right on the top over my tableview where i startet it and in a size i spezify without disturbing the tableview. I think i dont get the basics right. Can someone give me an outline how i have to define my class for that and what function i need to implement or override? -
hi
". and its shown as a regular window, "Are you sure u assign a parent?
QWidget *myw=new QWidget(this); // "this" is parent
QWidget *myw=new QWidget(); // no parent /default NULL)
-
To add to what @mrjj mentioned with the parent: You are actually supposed to assign the parent passed to the
createEditor()
function:QWidget* ComboboxDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const { Q_UNUSED(option) Q_UNUSED(index) QComboBox* combobox = new QComboBox(parent); combobox->addItems({"Foo", "Bar", "mrjj"}); return combobox; }
-
Well, my editor contains a number of images, from where i can choose one or several. as a markup that images are chosen i draw a red circle, around the activated ones. And the pictures are bigger, so they dont fit in the cell and the cell have to be resized when i draw it in the cell. So i figured i just draw it on top with a predefined size of a editorwidget.
-
-
@Maser
Hi,
Maybe you should look into a delegate ?
http://doc.qt.io/qt-5/qtwidgets-itemviews-stardelegate-example.htmlA delegate is the normal way to change how content is drawn in each cell.
Painting on the actual view will often have side effects with scrolling etc.
If you want to see, you will override the paintEvent virtual function
and paint there. -
Ok. Im not really following what u need. sorry.
In any case, you can override paintEvent for any widget and draw.
Notice that you cannot draw outside of the widgets client area so
make sure u override the paint for the actual widget u want to draw on. -
It seems overriding paintevent doesnt work. What does work(at least partially) is reimplementing updateEditorGeometry from the delegate. When i give the specific cell a bigger size for the editor it paints it bigger. Even the choosing works, but not when there is another cell under from the tableview under my editor-buttons. Dont yet know how to solve that.
-
http://www.picfront.org/d/9q7X
I marked the cell from which the editor has been activated. Problem is, as long is the items are of this cell or outside of the table, i can click them. if the are above other cells, the editor closes. -
@Maser
Could you not just pop a dialog with
all the images and let user select one?Or use a combobox with a delegate ?
http://www.qtcentre.org/threads/26376-Using-images-in-QComboBox -
This is a good idea)
But since im trying to learn Qt, i will save it for the emergency plan)
When i have a customer who wants it the exact way he described it, i wanna know how to do it, no matter of the cost)
Have you an idea why the over cells interfere with my editor and how i can solve it? -
No, i can. I told you. if i aim right in the black marked cell, i can click and unclick the three left items, i can also click the three right items. Just when i click anywhere in the tablecells, the editor is gone.
PS: Maybe i have to somehow resize the "working area" of the cell to to fit my editor. I mean the clickable area associated with the cell. Idea on that?