mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Use a dedicated widget for rendering the icon in message boxes rather than a QLabel. Maybe that will fix the problem of mis-rendered icons on OS X?
This commit is contained in:
parent
3e30513da6
commit
06cf81afbf
@ -7,14 +7,37 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
import sys
|
||||
|
||||
from PyQt5.Qt import (QDialog, QIcon, QApplication, QSize, QKeySequence,
|
||||
from PyQt5.Qt import (
|
||||
QPainter, QDialog, QIcon, QApplication, QSize, QKeySequence,
|
||||
QAction, Qt, QTextBrowser, QDialogButtonBox, QVBoxLayout, QGridLayout,
|
||||
QLabel, QPlainTextEdit, QTextDocument, QCheckBox, pyqtSignal)
|
||||
QLabel, QPlainTextEdit, QTextDocument, QCheckBox, pyqtSignal, QWidget,
|
||||
QSizePolicy)
|
||||
|
||||
from calibre.constants import __version__, isfrozen
|
||||
from calibre.gui2 import gprefs
|
||||
|
||||
|
||||
class Icon(QWidget):
|
||||
|
||||
def __init__(self, parent=None):
|
||||
QWidget.__init__(self, parent)
|
||||
self.pixmap = None
|
||||
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
|
||||
|
||||
def set_icon(self, qicon):
|
||||
self.pixmap = qicon.pixmap(64, 64)
|
||||
|
||||
def sizeHint(self):
|
||||
return QSize(64, 64)
|
||||
|
||||
def paintEvent(self, ev):
|
||||
if self.pixmap is not None:
|
||||
x = (self.width() - 64) // 2
|
||||
y = (self.height() - 64) // 2
|
||||
p = QPainter(self)
|
||||
p.drawPixmap(x, y, self.width(), self.height(), self.pixmap)
|
||||
|
||||
|
||||
class MessageBox(QDialog): # {{{
|
||||
|
||||
ERROR = 0
|
||||
@ -29,11 +52,8 @@ class MessageBox(QDialog): # {{{
|
||||
self.resize(497, 235)
|
||||
self.gridLayout = l = QGridLayout(self)
|
||||
l.setObjectName("gridLayout")
|
||||
self.icon_label = la = QLabel('')
|
||||
la.setMaximumSize(QSize(64, 64))
|
||||
la.setScaledContents(True)
|
||||
la.setObjectName("icon_label")
|
||||
l.addWidget(la)
|
||||
self.icon_widget = Icon(self)
|
||||
l.addWidget(self.icon_widget)
|
||||
self.msg = la = QLabel(self)
|
||||
la.setWordWrap(True), la.setMinimumWidth(400)
|
||||
la.setOpenExternalLinks(True)
|
||||
@ -75,7 +95,7 @@ class MessageBox(QDialog): # {{{
|
||||
|
||||
self.setWindowTitle(title)
|
||||
self.setWindowIcon(self.icon)
|
||||
self.icon_label.setPixmap(self.icon.pixmap(64, 64))
|
||||
self.icon_widget.set_icon(self.icon)
|
||||
self.msg.setText(msg)
|
||||
self.det_msg.setPlainText(det_msg)
|
||||
self.det_msg.setVisible(False)
|
||||
@ -339,9 +359,8 @@ class JobError(QDialog): # {{{
|
||||
self.setLayout(l)
|
||||
self.icon = QIcon(I('dialog_error.png'))
|
||||
self.setWindowIcon(self.icon)
|
||||
self.icon_label = QLabel()
|
||||
self.icon_label.setPixmap(self.icon.pixmap(68, 68))
|
||||
self.icon_label.setMaximumSize(QSize(68, 68))
|
||||
self.icon_widget = Icon(self)
|
||||
self.icon_widget.set_icon(self.icon)
|
||||
self.msg_label = QLabel('<p> ')
|
||||
self.msg_label.setStyleSheet('QLabel { margin-top: 1ex; }')
|
||||
self.msg_label.setWordWrap(True)
|
||||
@ -366,7 +385,7 @@ class JobError(QDialog): # {{{
|
||||
_('Show detailed information about this error'))
|
||||
self.suppress = QCheckBox(self)
|
||||
|
||||
l.addWidget(self.icon_label, 0, 0, 1, 1)
|
||||
l.addWidget(self.icon_widget, 0, 0, 1, 1)
|
||||
l.addWidget(self.msg_label, 0, 1, 1, 1)
|
||||
l.addWidget(self.det_msg, 1, 0, 1, 2)
|
||||
l.addWidget(self.suppress, 2, 0, 1, 2, Qt.AlignLeft|Qt.AlignBottom)
|
||||
|
Loading…
x
Reference in New Issue
Block a user