mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
This commit works the way I want, ensuring the checked button is focused while using 'vanilla' Qt. It doesn't work around the odd behavior of backtab.
Apologies for the multiple commits. I don't know what happens if I remove commits in a pull request so I left them all.
This commit is contained in:
parent
8d3d28da09
commit
9e5b656bd5
@ -13,7 +13,7 @@ from functools import partial
|
|||||||
from qt.core import (
|
from qt.core import (
|
||||||
QDialog, Qt, QColor, QIcon, QVBoxLayout, QLabel, QGridLayout,
|
QDialog, Qt, QColor, QIcon, QVBoxLayout, QLabel, QGridLayout,
|
||||||
QDialogButtonBox, QWidget, QLineEdit, QHBoxLayout, QComboBox,
|
QDialogButtonBox, QWidget, QLineEdit, QHBoxLayout, QComboBox,
|
||||||
QCheckBox, QSpinBox, QRadioButton, QGroupBox, pyqtSignal
|
QCheckBox, QSpinBox, QRadioButton, QGroupBox
|
||||||
)
|
)
|
||||||
|
|
||||||
from calibre.gui2 import error_dialog
|
from calibre.gui2 import error_dialog
|
||||||
@ -22,22 +22,6 @@ from calibre.utils.date import parse_date, UNDEFINED_DATE
|
|||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
|
|
||||||
|
|
||||||
class GroupBox(QGroupBox):
|
|
||||||
# A group box for radio buttons that acts passes along focus events so the
|
|
||||||
# correct child button is given the focus
|
|
||||||
|
|
||||||
got_focus = pyqtSignal()
|
|
||||||
|
|
||||||
def focusInEvent(self, ev):
|
|
||||||
# We need this backtab focus stuff because a backtab from a radio button
|
|
||||||
# gives the focus back to the group box instead of the next widget in the
|
|
||||||
# focus chain. For some reason a tab doesn't do that.
|
|
||||||
if ev.reason() != Qt.FocusReason.BacktabFocusReason:
|
|
||||||
self.got_focus.emit()
|
|
||||||
else:
|
|
||||||
self.focusNextPrevChild(False)
|
|
||||||
|
|
||||||
|
|
||||||
class CreateCustomColumn(QDialog):
|
class CreateCustomColumn(QDialog):
|
||||||
|
|
||||||
# Note: in this class, we are treating is_multiple as the boolean that
|
# Note: in this class, we are treating is_multiple as the boolean that
|
||||||
@ -193,11 +177,11 @@ class CreateCustomColumn(QDialog):
|
|||||||
icon = bool(c['display'].get('bools_show_icons', True))
|
icon = bool(c['display'].get('bools_show_icons', True))
|
||||||
txt = bool(c['display'].get('bools_show_text', False))
|
txt = bool(c['display'].get('bools_show_text', False))
|
||||||
if icon and txt:
|
if icon and txt:
|
||||||
self.bool_show_both_button.setChecked(True)
|
self.bool_show_both_button.click()
|
||||||
elif icon:
|
elif icon:
|
||||||
self.bool_show_icon_button.setChecked(True)
|
self.bool_show_icon_button.click()
|
||||||
else:
|
else:
|
||||||
self.bool_show_text_button.setChecked(True)
|
self.bool_show_text_button.click()
|
||||||
|
|
||||||
# Default values
|
# Default values
|
||||||
dv = c['display'].get('default_value', None)
|
dv = c['display'].get('default_value', None)
|
||||||
@ -342,15 +326,16 @@ class CreateCustomColumn(QDialog):
|
|||||||
|
|
||||||
# bool formatting
|
# bool formatting
|
||||||
h1 = QHBoxLayout()
|
h1 = QHBoxLayout()
|
||||||
self.bool_show_icon_button = QRadioButton(_('&Icon'))
|
def add_bool_radio_button(txt):
|
||||||
h1.addWidget(self.bool_show_icon_button)
|
b = QRadioButton(txt)
|
||||||
self.bool_show_text_button = QRadioButton(_('&Text'))
|
b.clicked.connect(partial(self.bool_radio_button_clicked, b))
|
||||||
h1.addWidget(self.bool_show_text_button)
|
h1.addWidget(b)
|
||||||
self.bool_show_both_button = QRadioButton(_('&Both'))
|
return b
|
||||||
h1.addWidget(self.bool_show_both_button)
|
self.bool_show_icon_button = add_bool_radio_button(_('&Icon'))
|
||||||
self.bool_button_group = GroupBox()
|
self.bool_show_text_button = add_bool_radio_button(_('&Text'))
|
||||||
self.bool_button_group.setFocusPolicy(Qt.StrongFocus)
|
self.bool_show_both_button = add_bool_radio_button(_('&Both'))
|
||||||
self.bool_button_group.got_focus.connect(self.bool_groupbox_focused)
|
self.bool_button_group = QGroupBox()
|
||||||
|
self.bool_button_group.setFocusPolicy(Qt.FocusPolicy.StrongFocus)
|
||||||
self.bool_button_group.setLayout(h1)
|
self.bool_button_group.setLayout(h1)
|
||||||
h = QHBoxLayout()
|
h = QHBoxLayout()
|
||||||
h.addWidget(self.bool_button_group)
|
h.addWidget(self.bool_button_group)
|
||||||
@ -470,13 +455,9 @@ class CreateCustomColumn(QDialog):
|
|||||||
self.resize(self.sizeHint())
|
self.resize(self.sizeHint())
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
def bool_groupbox_focused(self):
|
def bool_radio_button_clicked(self, button, clicked):
|
||||||
if self.bool_show_icon_button.isChecked():
|
if clicked:
|
||||||
self.bool_show_icon_button.setFocus()
|
self.bool_button_group.setFocusProxy(button)
|
||||||
elif self.bool_show_text_button.isChecked():
|
|
||||||
self.bool_show_text_button.setFocus()
|
|
||||||
else:
|
|
||||||
self.bool_show_both_button.setFocus()
|
|
||||||
|
|
||||||
def datatype_changed(self, *args):
|
def datatype_changed(self, *args):
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user