Re: [PySide] editing selected cells in QTabelWidget

2022-08-31 Thread David Ching
> From: Frank Rueter mailto:fr...@ohufx.com 
> Thanks, I solved that part by not using the persistent editor at all as that 
> seemed to interrupt things.
> Instead I just use the mousePressEvent on the table to make single clicks 
> edit the cells. Then I have 
> the delegate's setModelData method deal with bulk editing selected rows.
> This seems to work really well and is quite transparent in the code so I am 
> happy for now.
> 
> Thanks for holding my hand!

Great! I am glad to help, I wish continued traffic on the mailing list as I 
think the PySide community is really great, but you don’t get a sense of that. 
It seems most of the users are very niche so there is not some industry swell 
around any one thing about it.

Cheers,
David




___
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside


Re: [PySide] editing selected cells in QTabelWidget

2022-08-31 Thread Frank Rueter
Thanks, I solved that part by not using the persistent editor at all as
that seemed to interrupt things.
Instead I just use the mousePressEvent on the table to make single clicks
edit the cells. Then I have the delegate's setModelData method deal with
bulk editing selected rows.
This seems to work really well and is quite transparent in the code so I am
happy for now.

Thanks for holding my hand!

frank

On Wed, Aug 31, 2022 at 3:54 AM David Ching  wrote:

> Even if you got the right click to actually set focus to the combo box on
> one item, I am not sure the user would find that intuitive.  Right-clicking
> usually brings up a context menu.  On deeper thought, it seems to be a
> conflict of using the persistent editor with a selection of multiple items.
> It's not standard.  I would instead propose:
>
> Insert a first column of checkmark controls.  Selecting an item checks this
> checkbox.  In the end, multiple selections will have checkmarks.  Then you
> can single click a combo box as normal, change the selection, and have it
> apply to all the items with checkmarks.  Would that work for you?
>
> Thanks,
> David
>
>
> > From: PySide  On Behalf Of Frank Rueter
> > Sent: Friday, August 26, 2022 3:05 AM
> > Subject: Re: [PySide] editing selected cells in QTabelWidget
>
> > So I made some progress but am now having the problem that a right click
> >  on a persistent editor (combo box) will lose the current table
> selection.
>
> > [...]
>
>
>
>
___
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside


Re: [PySide] editing selected cells in QTabelWidget

2022-08-30 Thread David Ching
Even if you got the right click to actually set focus to the combo box on
one item, I am not sure the user would find that intuitive.  Right-clicking
usually brings up a context menu.  On deeper thought, it seems to be a
conflict of using the persistent editor with a selection of multiple items.
It's not standard.  I would instead propose:

Insert a first column of checkmark controls.  Selecting an item checks this
checkbox.  In the end, multiple selections will have checkmarks.  Then you
can single click a combo box as normal, change the selection, and have it
apply to all the items with checkmarks.  Would that work for you?

Thanks,
David


> From: PySide  On Behalf Of Frank Rueter
> Sent: Friday, August 26, 2022 3:05 AM
> Subject: Re: [PySide] editing selected cells in QTabelWidget

> So I made some progress but am now having the problem that a right click
>  on a persistent editor (combo box) will lose the current table selection.

> [...]



___
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside


Re: [PySide] editing selected cells in QTabelWidget

2022-08-26 Thread Keith Kyzivat
Hi Frank,

You should be able to suppress the single click deselect using an event filter.
You create (or use an existing) QObject that will receive all events that are 
sent to the QObject that you install the event filter on, and from that, you 
define an `eventFilter(obj: QObject, event: QEvent) -> bool` method on that 
which will do the event filtering.

From that method, you can look at the events type, looking for 
`QEvent.MouseButtonPress` or `QEvent.MouseButtonRelease` (not sure which is 
actually triggering the unselect), and just return `True` from the event filter 
in those cases. All other cases, you just return the parent’s implementation of 
eventFilter, passing the same object and event.

This way you achieve suppression of the mousePress and mouseRelease.

(I tried my best to translate these to Python, but these might not be 100% 
correct).

~Keith

From: PySide  On Behalf Of Frank Rueter
Sent: Friday, August 26, 2022 3:05 AM
To: David Ching 
Cc: pyside@qt-project.org
Subject: Re: [PySide] editing selected cells in QTabelWidget

So I made some progress but am now having the problem that a right click on a 
persistent editor (combo box) will lose the current table selection. I tried 
reimplementing the mousePressEvent on both the editor widget and the actual 
table widget to stop that behaviour but to no avail.
Here is a simplified version of the code that shows the problem:
https://pastebin.com/M9RSTFSJ
[cid:image001.png@01D8B937.5E6EA900]
What I am trying to achieve is that a right click on the editor ithe "Type" 
column will keep the current row selection, so that I can then pop up the 
editor and apply the new value to all selected rows.

What am I missing?

Cheers,
frank

On Fri, Aug 26, 2022 at 7:58 AM Frank Rueter 
mailto:fr...@ohufx.com>> wrote:
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 
mailto:d...@dcsoft.com>> wrote:
> Date: Thu, 25 Aug 2022 20:36:01 +1200
> From: Frank Rueter mailto:fr...@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@qt-project.org<mailto:PySide@qt-project.org>
https://lists.qt-project.org/listinfo/pyside
___
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside


Re: [PySide] editing selected cells in QTabelWidget

2022-08-26 Thread Frank Rueter
So I made some progress but am now having the problem that a right click on
a persistent editor (combo box) will lose the current table selection. I
tried reimplementing the mousePressEvent on both the editor widget and the
actual table widget to stop that behaviour but to no avail.
Here is a simplified version of the code that shows the problem:
https://pastebin.com/M9RSTFSJ
[image: image.png]
What I am trying to achieve is that a right click on the editor ithe "Type"
column will keep the current row selection, so that I can then pop up the
editor and apply the new value to all selected rows.

What am I missing?

Cheers,
frank

On Fri, Aug 26, 2022 at 7:58 AM Frank Rueter  wrote:

> 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  wrote:
>
>> > Date: Thu, 25 Aug 2022 20:36:01 +1200
>> > From: Frank Rueter 
>> > 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@qt-project.org
>> https://lists.qt-project.org/listinfo/pyside
>>
>
___
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside


Re: [PySide] editing selected cells in QTabelWidget

2022-08-25 Thread Frank Rueter
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  wrote:

> > Date: Thu, 25 Aug 2022 20:36:01 +1200
> > From: Frank Rueter 
> > 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@qt-project.org
> https://lists.qt-project.org/listinfo/pyside
>
___
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside


Re: [PySide] editing selected cells in QTabelWidget

2022-08-25 Thread David Ching
> Date: Thu, 25 Aug 2022 20:36:01 +1200
> From: Frank Rueter 
> 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@qt-project.org
https://lists.qt-project.org/listinfo/pyside