Skip to content

Commit

Permalink
fix: retain pointers in QCheckableTabWidget (#220)
Browse files Browse the repository at this point in the history
retain pointers
  • Loading branch information
tlambert03 authored Oct 7, 2023
1 parent 7b2aa01 commit 94d36fa
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/pymmcore_widgets/_mda/_checkable_tabwidget_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(

self.change_tab_on_check = change_tab_on_check
self.tabBar().setElideMode(Qt.TextElideMode.ElideNone)
self._cboxes: list[QCheckBox] = []

def isChecked(
self,
Expand Down Expand Up @@ -173,15 +174,17 @@ def insertTab(
) -> int:
"""Insert `widget` in a tab with a checkable QCheckbox at the given index."""
super().insertTab(index, widget, *args)
self._cbox = QCheckBox(parent=self.tabBar())
cbox = QCheckBox(parent=self)
# not sure why, but retaining a pointer to cbox seems to be necessary
# for self.tabBar().tabButton(idx, position) to later return a QCheckBox
# (instead of some other QWidget).
self._cboxes.append(cbox)
if widget is not None:
widget.setEnabled(checked)
self._cbox.toggled.connect(
lambda c: self._on_tab_checkbox_toggled(c, widget)
)
cbox.toggled.connect(lambda c: self._on_tab_checkbox_toggled(c, widget))
if tab_bar := self.tabBar():
tab_bar.setTabButton(index, position, self._cbox)
self._cbox.setChecked(checked)
tab_bar.setTabButton(index, position, cbox)
cbox.setChecked(checked)
return index

def _on_tab_checkbox_toggled(self, checked: bool, wdg: QWidget) -> None:
Expand Down

0 comments on commit 94d36fa

Please sign in to comment.