From e095f5d0cf08ffab5463e424ffb67f3cdb15e67d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 5 Jun 2012 16:51:37 +0530 Subject: [PATCH] Fix multiple buttons being highlighted when a button box has focus --- src/calibre/gui2/metadata/single.py | 4 +++- src/calibre/gui2/preferences/main.py | 5 +++-- src/calibre/gui2/proceed.py | 4 ++-- src/qtcurve/style/qtcurve.cpp | 14 +++++++++++++- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/calibre/gui2/metadata/single.py b/src/calibre/gui2/metadata/single.py index 3ca543cd89..bb69197b58 100644 --- a/src/calibre/gui2/metadata/single.py +++ b/src/calibre/gui2/metadata/single.py @@ -512,6 +512,8 @@ class MetadataSingleDialogBase(ResizableDialog): ' [Alt+Left]')%prev self.prev_button.setToolTip(tip) self.prev_button.setEnabled(prev is not None) + self.button_box.button(self.button_box.Ok).setDefault(True) + self.button_box.button(self.button_box.Ok).setFocus(Qt.OtherFocusReason) self(self.db.id(self.row_list[self.current_row])) def break_cycles(self): @@ -980,7 +982,7 @@ def edit_metadata(db, row_list, current_row, parent=None, view_slot=None, return d.changed, d.rows_to_refresh if __name__ == '__main__': - from PyQt4.Qt import QApplication + from calibre.gui2 import Application as QApplication app = QApplication([]) from calibre.library import db as db_ db = db_() diff --git a/src/calibre/gui2/preferences/main.py b/src/calibre/gui2/preferences/main.py index 0f3d29f454..98b5f168b3 100644 --- a/src/calibre/gui2/preferences/main.py +++ b/src/calibre/gui2/preferences/main.py @@ -211,6 +211,7 @@ class Preferences(QMainWindow): self.wizard_button.clicked.connect(self.run_wizard, type=Qt.QueuedConnection) self.cw.layout().addWidget(self.bb) + self.bb.button(self.bb.Close).setDefault(True) self.bb.rejected.connect(self.close, type=Qt.QueuedConnection) self.setCentralWidget(self.cw) self.browser = Browser(self) @@ -380,8 +381,8 @@ class Preferences(QMainWindow): return QMainWindow.closeEvent(self, *args) if __name__ == '__main__': - from PyQt4.Qt import QApplication - app = QApplication([]) + from calibre.gui2 import Application + app = Application([]) app gui = init_gui() diff --git a/src/calibre/gui2/proceed.py b/src/calibre/gui2/proceed.py index f6cd453f77..1074792096 100644 --- a/src/calibre/gui2/proceed.py +++ b/src/calibre/gui2/proceed.py @@ -122,10 +122,10 @@ class ProceedQuestion(QDialog): self.det_msg.setVisible(False) self.det_msg_toggle.setVisible(bool(question.det_msg)) self.det_msg_toggle.setText(self.show_det_msg) - self.bb.button(self.bb.Yes).setDefault(True) self.do_resize() - self.bb.button(self.bb.Yes).setFocus(Qt.OtherFocusReason) self.show() + self.bb.button(self.bb.Yes).setDefault(True) + self.bb.button(self.bb.Yes).setFocus(Qt.OtherFocusReason) def __call__(self, callback, payload, html_log, log_viewer_title, title, msg, det_msg='', show_copy_button=False, cancel_callback=None, diff --git a/src/qtcurve/style/qtcurve.cpp b/src/qtcurve/style/qtcurve.cpp index 07987c2e88..06da504d81 100644 --- a/src/qtcurve/style/qtcurve.cpp +++ b/src/qtcurve/style/qtcurve.cpp @@ -6449,7 +6449,19 @@ void Style::drawControl(ControlElement element, const QStyleOption *option, QPai // For OO.o 3.2 need to fill widget background! if(isOOWidget(widget)) painter->fillRect(r, palette.brush(QPalette::Window)); - drawControl(CE_PushButtonBevel, btn, painter, widget); + + // Changed by Kovid: Buttons in a ButtonBox have a default + // which is highlighted with a glow. If another button in the + // button box has input focus that will also be highlighted + // with a glow, resulting in two highlighted buttons. So nuke + // the has focus indicator. Interestingly, changing focus with + // the tab key still causes the focused button (and only the + // focussed button) to be highlighted. I dont really understand + // this, but whatever. + QStyleOptionButton foc_opt(*btn); + if (widget && widget->parent() && widget->parent()->inherits("QDialogButtonBox")) + foc_opt.state &= ~State_HasFocus; + drawControl(CE_PushButtonBevel, &foc_opt, painter, widget); QStyleOptionButton subopt(*btn);