Add a tweak to change the font size of the AI chat widget. Fixes #2138862 [[Enhancement] Set Font Size for Ask AI](https://bugs.launchpad.net/calibre/+bug/2138862)

This commit is contained in:
Kovid Goyal 2026-01-22 17:17:52 +05:30
parent ff4d1faaab
commit ec0de325e0
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 26 additions and 2 deletions

View File

@ -461,8 +461,10 @@ gui_view_history_size = 15
#: Change the font size of the Book details panel in the interface
# Change the font size at which book details are rendered in the side panel and
# comments are rendered in the metadata edit dialog. Set it to a positive or
# negative number to increase or decrease the font size.
# negative number to increase or decrease the font size. Similarly, change the
# font size of the widget used to converse with AI.
change_book_details_font_size_by = 0
change_ai_chat_font_size_by = 0
#: What format to default to when using the "Unpack book" feature
# The "Unpack book" feature of calibre allows direct editing of a book format.

View File

@ -5,8 +5,26 @@ from html import escape
from math import ceil
from typing import NamedTuple
from qt.core import QFrame, QHBoxLayout, QIcon, QPalette, QSize, QSizePolicy, Qt, QTextBrowser, QTextEdit, QToolButton, QUrl, QVBoxLayout, QWidget, pyqtSignal
from qt.core import (
QFont,
QFontInfo,
QFrame,
QHBoxLayout,
QIcon,
QPalette,
QSize,
QSizePolicy,
Qt,
QTextBrowser,
QTextEdit,
QToolButton,
QUrl,
QVBoxLayout,
QWidget,
pyqtSignal,
)
from calibre.utils.config_base import tweaks
from calibre.utils.logging import INFO, WARN
from calibre.utils.resources import get_image_path
@ -21,6 +39,10 @@ class Browser(QTextBrowser):
self.setContentsMargins(0, 0, 0, 0)
self.document().setDocumentMargin(0)
self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
if tweaks['change_ai_chat_font_size_by']:
font = QFont(self.font())
font.setPixelSize(QFontInfo(font).pixelSize() + tweaks['change_ai_chat_font_size_by'])
self.setFont(font)
def sizeHint(self) -> QSize:
return QSize(600, 500)