mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Ignore all exceptions in the font family chooser widget
This commit is contained in:
parent
9070385bb7
commit
a69112b3e4
@ -55,6 +55,12 @@ def writing_system_for_font(font):
|
|||||||
class FontFamilyDelegate(QStyledItemDelegate):
|
class FontFamilyDelegate(QStyledItemDelegate):
|
||||||
|
|
||||||
def sizeHint(self, option, index):
|
def sizeHint(self, option, index):
|
||||||
|
try:
|
||||||
|
return self.do_size_hint(option, index)
|
||||||
|
except:
|
||||||
|
return QSize(300, 50)
|
||||||
|
|
||||||
|
def do_size_hint(self, option, index):
|
||||||
text = index.data(Qt.DisplayRole).toString()
|
text = index.data(Qt.DisplayRole).toString()
|
||||||
font = QFont(option.font)
|
font = QFont(option.font)
|
||||||
font.setPointSize(QFontInfo(font).pointSize() * 1.5)
|
font.setPointSize(QFontInfo(font).pointSize() * 1.5)
|
||||||
@ -62,6 +68,14 @@ class FontFamilyDelegate(QStyledItemDelegate):
|
|||||||
return QSize(m.width(text), m.height())
|
return QSize(m.width(text), m.height())
|
||||||
|
|
||||||
def paint(self, painter, option, index):
|
def paint(self, painter, option, index):
|
||||||
|
painter.save()
|
||||||
|
try:
|
||||||
|
self.do_paint(painter, option, index)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
painter.restore()
|
||||||
|
|
||||||
|
def do_paint(self, painter, option, index):
|
||||||
text = unicode(index.data(Qt.DisplayRole).toString())
|
text = unicode(index.data(Qt.DisplayRole).toString())
|
||||||
font = QFont(option.font)
|
font = QFont(option.font)
|
||||||
font.setPointSize(QFontInfo(font).pointSize() * 1.5)
|
font.setPointSize(QFontInfo(font).pointSize() * 1.5)
|
||||||
@ -75,7 +89,6 @@ class FontFamilyDelegate(QStyledItemDelegate):
|
|||||||
r = option.rect
|
r = option.rect
|
||||||
|
|
||||||
if option.state & QStyle.State_Selected:
|
if option.state & QStyle.State_Selected:
|
||||||
painter.save()
|
|
||||||
painter.setBrush(option.palette.highlight())
|
painter.setBrush(option.palette.highlight())
|
||||||
painter.setPen(Qt.NoPen)
|
painter.setPen(Qt.NoPen)
|
||||||
painter.drawRect(option.rect)
|
painter.drawRect(option.rect)
|
||||||
@ -102,9 +115,6 @@ class FontFamilyDelegate(QStyledItemDelegate):
|
|||||||
|
|
||||||
painter.setFont(old)
|
painter.setFont(old)
|
||||||
|
|
||||||
if (option.state & QStyle.State_Selected):
|
|
||||||
painter.restore()
|
|
||||||
|
|
||||||
class FontFamilyChooser(QComboBox):
|
class FontFamilyChooser(QComboBox):
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
@ -138,7 +148,10 @@ class FontFamilyChooser(QComboBox):
|
|||||||
|
|
||||||
def sizeHint(self):
|
def sizeHint(self):
|
||||||
ans = QComboBox.sizeHint(self)
|
ans = QComboBox.sizeHint(self)
|
||||||
|
try:
|
||||||
ans.setWidth(QFontMetrics(self.font()).width('m'*14))
|
ans.setWidth(QFontMetrics(self.font()).width('m'*14))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
@dynamic_property
|
@dynamic_property
|
||||||
@ -157,12 +170,15 @@ class FontFamilyChooser(QComboBox):
|
|||||||
self.setCurrentIndex(idx)
|
self.setCurrentIndex(idx)
|
||||||
return property(fget=fget, fset=fset)
|
return property(fget=fget, fset=fset)
|
||||||
|
|
||||||
|
def test():
|
||||||
if __name__ == '__main__':
|
|
||||||
app = QApplication([])
|
app = QApplication([])
|
||||||
|
app
|
||||||
d = QDialog()
|
d = QDialog()
|
||||||
d.setLayout(QVBoxLayout())
|
d.setLayout(QVBoxLayout())
|
||||||
d.layout().addWidget(FontFamilyChooser(d))
|
d.layout().addWidget(FontFamilyChooser(d))
|
||||||
d.layout().addWidget(QFontComboBox(d))
|
d.layout().addWidget(QFontComboBox(d))
|
||||||
d.exec_()
|
d.exec_()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
test()
|
||||||
|
|
||||||
|
@ -139,3 +139,5 @@ class MainWindow(QMainWindow):
|
|||||||
show=True)
|
show=True)
|
||||||
except BaseException:
|
except BaseException:
|
||||||
pass
|
pass
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user