Fix multiple buttons being highlighted when a button box has focus

This commit is contained in:
Kovid Goyal 2012-06-05 16:51:37 +05:30
parent d4c4403a1f
commit e095f5d0cf
4 changed files with 21 additions and 6 deletions

View File

@ -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_()

View File

@ -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()

View File

@ -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,

View File

@ -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);