Discussion:
[PySide] crash when using multiple setSectionResizeMode() calls in QTableView
Frank Rueter | OHUfx
2018-08-13 03:17:02 UTC
Permalink
Hi all,

using PySide2 I am trying to set different resize modes for each of my
columns in a table view, but as soon as I set more than one I get a crash.

Here is what I do:

|class MyView(QtWidgets.QTableView): def __init__(self, parent=None):
super(MyView, self).__init__(parent) header = self.horizontalHeader()
header.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
header.setSectionResizeMode(1, QtWidgets.QHeaderView.Interactive) |

Is this a bug or am I doing something wrong?

Cheers,
frank

​
--
ohufxLogo 50x50 <http://www.ohufx.com>
*vfx compositing <http://ohufx.com/compositing.html> | *workflow
customisation and consulting <http://ohufx.com/customising.html>* *
*<http://ohufx.com/compositing.html>*
<http://www.nukepedia.com/nubridge>


Your gateway to over 1,000 free tools... right inside of Nuke
<http://www.nukepedia.com/nubridge>
Frank Rueter | OHUfx
2018-08-13 09:30:31 UTC
Permalink
Thanks. My header data simply looks like this:

|def headerData(self, section, orientation, role): if orientation ==
QtCore.Qt.Horizontal: if role == QtCore.Qt.DisplayRole: return
self.header_labels[section] |

where: self.header_labels just contains a list of strings.

I guess I need to implement size hint roles?! I will try that tomorrow.

Tanks for the tip!

Cheers,
frank
Must be something in your code; I'd start by double-checking everything
related to the header data in your model.
-Marian
Post by Frank Rueter | OHUfx
Hi all,
using PySide2 I am trying to set different resize modes for each of my
columns in a table view, but as soon as I set more than one I get a crash.
super(MyView, self).__init__(parent) header = self.horizontalHeader()
header.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
header.setSectionResizeMode(1, QtWidgets.QHeaderView.Interactive) |
Is this a bug or am I doing something wrong?
Cheers,
frank
​
--
ohufxLogo 50x50 <http://www.ohufx.com>
*vfx compositing <http://ohufx.com/compositing.html> | *workflow
customisation and consulting <http://ohufx.com/customising.html>* *
    *<http://ohufx.com/compositing.html>*
<http://www.nukepedia.com/nubridge>
Your gateway to over 1,000 free tools... right inside of Nuke
<http://www.nukepedia.com/nubridge>
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
​
Frank Rueter | OHUfx
2018-08-14 00:17:37 UTC
Permalink
Thanks for testing Marian, much appreciated!
Interesting it won't crash for you. I will try it in a different IDE
(using WingIDE normally) and a different machine in case there is
something wrong with my install.

Cheers,
frank
I tried your setSectionResizeMode snippet on a table model
whose headerData() is the same as yours and it doesn't cause a crash for
me. I don't think the other roles are required (at least to not have a
crash).
Post by Frank Rueter | OHUfx
|def headerData(self, section, orientation, role): if orientation ==
QtCore.Qt.Horizontal: if role == QtCore.Qt.DisplayRole: return
self.header_labels[section] |
where: self.header_labels just contains a list of strings.
I guess I need to implement size hint roles?! I will try that tomorrow.
Tanks for the tip!
Cheers,
frank
Must be something in your code; I'd start by double-checking everything
related to the header data in your model.
-Marian
Post by Frank Rueter | OHUfx
Hi all,
using PySide2 I am trying to set different resize modes for each of my
columns in a table view, but as soon as I set more than one I get a crash.
super(MyView, self).__init__(parent) header = self.horizontalHeader()
header.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
header.setSectionResizeMode(1, QtWidgets.QHeaderView.Interactive) |
Is this a bug or am I doing something wrong?
Cheers,
frank

--
ohufxLogo 50x50 <http://www.ohufx.com>
*vfx compositing <http://ohufx.com/compositing.html> | *workflow
customisation and consulting <http://ohufx.com/customising.html>* *
    *<http://ohufx.com/compositing.html>*
<http://www.nukepedia.com/nubridge>
Your gateway to over 1,000 free tools... right inside of Nuke
<http://www.nukepedia.com/nubridge>
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest

Frank Rueter | OHUfx
2018-08-15 00:34:37 UTC
Permalink
Hi,

I isolated the problem into a small snippet:
https://gitlab.com/snippets/1744780

This still crashes for me.

I do get the result I’m after by only setting one resize mode, i.e.:

|header.setSectionResizeMode(5, QtWidgets.QHeaderView.Fixed) |

However, what I’m really after is the behaviour of

|header.setStretchLastSection(True) |

but I need the second last section to stretch while the last one remains
a fixes size.
Is there a way to do this or do I have to write my own header view for that?

Cheers,
frank
Post by Frank Rueter | OHUfx
Thanks for testing Marian, much appreciated!
Interesting it won't crash for you. I will try it in a different IDE
(using WingIDE normally) and a different machine in case there is
something wrong with my install.
Cheers,
frank
I tried your setSectionResizeMode snippet on a table model
whose headerData() is the same as yours and it doesn't cause a crash for
me. I don't think the other roles are required (at least to not have a
crash).
Post by Frank Rueter | OHUfx
|def headerData(self, section, orientation, role): if orientation ==
QtCore.Qt.Horizontal: if role == QtCore.Qt.DisplayRole: return
self.header_labels[section] |
where: self.header_labels just contains a list of strings.
I guess I need to implement size hint roles?! I will try that tomorrow.
Tanks for the tip!
Cheers,
frank
Must be something in your code; I'd start by double-checking everything
related to the header data in your model.
-Marian
Post by Frank Rueter | OHUfx
Hi all,
using PySide2 I am trying to set different resize modes for each of my
columns in a table view, but as soon as I set more than one I get a crash.
super(MyView, self).__init__(parent) header = self.horizontalHeader()
header.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
header.setSectionResizeMode(1, QtWidgets.QHeaderView.Interactive) |
Is this a bug or am I doing something wrong?
Cheers,
frank
​
--
ohufxLogo 50x50 <http://www.ohufx.com>
    *vfx compositing <http://ohufx.com/compositing.html> | *workflow
customisation and consulting <http://ohufx.com/customising.html>* *
*<http://ohufx.com/compositing.html>*
<http://www.nukepedia.com/nubridge>
Your gateway to over 1,000 free tools... right inside of Nuke
<http://www.nukepedia.com/nubridge>
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
​
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
​
Frank Rueter | OHUfx
2018-08-15 10:55:28 UTC
Permalink
Ha, you are a star! I will try that first thing in the morning!

Thanks!
frank
Hi Frank,
I didn't spot it earlier, but now I saw it. You're manipulating
QHeaderView's sections before setting the model on the view. Most things
you can do with a QHeaderView require a model to be present.
If you move these calls to after a model has been set, everything works.
https://gist.github.com/enkore/727e3f912c8f9380017fb78591f2a05e
-Marian
Post by Frank Rueter | OHUfx
Hi,
https://gitlab.com/snippets/1744780
This still crashes for me.
|header.setSectionResizeMode(5, QtWidgets.QHeaderView.Fixed) |
However, what I’m really after is the behaviour of
|header.setStretchLastSection(True) |
but I need the second last section to stretch while the last one remains
a fixes size.
Is there a way to do this or do I have to write my own header view for that?
Cheers,
frank
Post by Frank Rueter | OHUfx
Thanks for testing Marian, much appreciated!
Interesting it won't crash for you. I will try it in a different IDE
(using WingIDE normally) and a different machine in case there is
something wrong with my install.
Cheers,
frank
I tried your setSectionResizeMode snippet on a table model
whose headerData() is the same as yours and it doesn't cause a crash for
me. I don't think the other roles are required (at least to not have a
crash).
Post by Frank Rueter | OHUfx
|def headerData(self, section, orientation, role): if orientation ==
QtCore.Qt.Horizontal: if role == QtCore.Qt.DisplayRole: return
self.header_labels[section] |
where: self.header_labels just contains a list of strings.
I guess I need to implement size hint roles?! I will try that tomorrow.
Tanks for the tip!
Cheers,
frank
Must be something in your code; I'd start by double-checking everything
related to the header data in your model.
-Marian
Post by Frank Rueter | OHUfx
Hi all,
using PySide2 I am trying to set different resize modes for each of my
columns in a table view, but as soon as I set more than one I get a crash.
super(MyView, self).__init__(parent) header = self.horizontalHeader()
header.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
header.setSectionResizeMode(1, QtWidgets.QHeaderView.Interactive) |
Is this a bug or am I doing something wrong?
Cheers,
frank

--
ohufxLogo 50x50 <http://www.ohufx.com>
    *vfx compositing <http://ohufx.com/compositing.html> | *workflow
customisation and consulting <http://ohufx.com/customising.html>* *
             *<http://ohufx.com/compositing.html>*
<http://www.nukepedia.com/nubridge>
Your gateway to over 1,000 free tools... right inside of Nuke
<http://www.nukepedia.com/nubridge>
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest

_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest

Loading...