[PySide] editing selected cells in QTabelWidget
Frank Rueter
frank at ohufx.com
Thu Aug 25 21:58:46 CEST 2022
Thanks David,
I was thinking about a right click option as a Plan B. Will do that.
I will look into using a delegate as well. I had forgotten I could use
those with the TableWidget as well.
Thanks!
Frank
On Fri, Aug 26, 2022 at 4:52 AM David Ching <dc at dcsoft.com> wrote:
> > Date: Thu, 25 Aug 2022 20:36:01 +1200
> > From: Frank Rueter <frank at ohufx.com>
> > Subject: [PySide] editing selected cells in QTabelWidget
> > Hi all,
> >
> > I have a simple table which will never hold much data, so I opted for
> QTabelWidget rather than QTabelView.
> > Two columns have combo boxes set as cell widgets; all other cells house
> straight up strings.
> >
> > I have set the selection behaviour to QAbstractItemView.SelectRows and am
> now trying to figure out how to enable
> > editing of selected cells, so that the user can select multiple rows,
> then double click a cell in that selection and edit it,
> > which will cause all other cells in the same column within the selection
> to receive the new value.
> >
> > I have hit a couple of issues:
> >
> > 1. By default the selection is reset when I double click in a cell, so I
> assume I will have to override QTableWidget.mousePressEvent() to prevent
> that somehow. Any suggestions on how to best manage that best? I am not
> sure what I need to re-implement to just prevent the selection being
> reset.
>
> In general, double clicking on a multiple selection doesn't work since as
> you note, the first click (of the double click) selects the single item
> that
> was clicked and de-selects the other items. To edit multiple selected
> items
> (my app runs on Windows) I select them and then start editing by pressing
> F2
> (which Excel uses similarly) or a toolbar button, or right-clicking one of
> the selected items which opens a context menu with an Edit item.
>
>
> > 2. the cell widgets do not modify the actual cell item's value. Do I
> > need to manually connect the widgets to a slot that will do that or is
> > there a better way to do that?
>
> I had a similar task:
>
> MyTableWidget::MyTableWidget(QWidget *parent) : QTableWidget(parent)
> {
> m_delegate = new MyTableItemDelegate(); // MyTableItemDelegate is
> derived from QStyledItemDelegate
> setItemDelegate(m_delegate);
> }
>
> MyTableItemDelegate overrides createEditor(), setEditorData(),
> setModelData(), updateEditorGeometry().
>
> Apologies, this code is in C++. It has been years since I developed this
> code, so don't know more details off the top of my head.
>
> Hope this helps,
> David
>
>
>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> https://lists.qt-project.org/listinfo/pyside
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20220826/c0514607/attachment.htm>
More information about the PySide
mailing list