Modify the style to show a scroll bar for combo boxes

This commit is contained in:
Veronica Berglyd Olsen
2025-06-19 19:29:14 +02:00
parent 110d8b8e59
commit dbf0b5d3f7
5 changed files with 21 additions and 7 deletions
+2 -1
View File
@@ -296,7 +296,8 @@ def _createApp(style: str) -> QApplication:
"""Create the app. This is done in a function to make it easier to """Create the app. This is done in a function to make it easier to
block app creation during testing. block app creation during testing.
""" """
app = QApplication([CONFIG.appName, f"-style={style}"]) app = QApplication([CONFIG.appName])
app.setStyle(style)
app.setApplicationName(CONFIG.appName) app.setApplicationName(CONFIG.appName)
app.setApplicationVersion(__version__) app.setApplicationVersion(__version__)
app.setOrganizationDomain(__domain__) app.setOrganizationDomain(__domain__)
+4 -4
View File
@@ -28,13 +28,13 @@ import logging
from PyQt6.QtCore import pyqtSlot from PyQt6.QtCore import pyqtSlot
from PyQt6.QtWidgets import ( from PyQt6.QtWidgets import (
QAbstractItemView, QComboBox, QDialogButtonBox, QGridLayout, QLabel, QAbstractItemView, QDialogButtonBox, QGridLayout, QLabel, QListWidget,
QListWidget, QListWidgetItem, QVBoxLayout, QWidget QListWidgetItem, QVBoxLayout, QWidget
) )
from novelwriter import SHARED from novelwriter import SHARED
from novelwriter.extensions.configlayout import NColorLabel from novelwriter.extensions.configlayout import NColorLabel
from novelwriter.extensions.modified import NDialog from novelwriter.extensions.modified import NComboBox, NDialog
from novelwriter.extensions.switch import NSwitch from novelwriter.extensions.switch import NSwitch
from novelwriter.types import QtAccepted, QtDialogCancel, QtDialogOk, QtUserRole from novelwriter.types import QtAccepted, QtDialogCancel, QtDialogOk, QtUserRole
@@ -79,7 +79,7 @@ class GuiDocSplit(NDialog):
self.listBox.setMinimumWidth(400) self.listBox.setMinimumWidth(400)
self.listBox.setMinimumHeight(180) self.listBox.setMinimumHeight(180)
self.splitLevel = QComboBox(self) self.splitLevel = NComboBox(self)
self.splitLevel.addItem(self.tr("Split on Heading Level 1 (Partition)"), 1) self.splitLevel.addItem(self.tr("Split on Heading Level 1 (Partition)"), 1)
self.splitLevel.addItem(self.tr("Split up to Heading Level 2 (Chapter)"), 2) self.splitLevel.addItem(self.tr("Split up to Heading Level 2 (Chapter)"), 2)
self.splitLevel.addItem(self.tr("Split up to Heading Level 3 (Scene)"), 3) self.splitLevel.addItem(self.tr("Split up to Heading Level 3 (Scene)"), 3)
+8 -1
View File
@@ -117,12 +117,19 @@ class NTreeView(QTreeView):
class NComboBox(QComboBox): class NComboBox(QComboBox):
def __init__(self, parent: QWidget | None = None) -> None: def __init__(self, parent: QWidget | None = None, maxItems: int = 15) -> None:
super().__init__(parent=parent) super().__init__(parent=parent)
self.setFocusPolicy(Qt.FocusPolicy.StrongFocus) self.setFocusPolicy(Qt.FocusPolicy.StrongFocus)
self.setMaxVisibleItems(maxItems)
# The style sheet disables Fusion style pop-up mode on some platforms
# and allows for scrolling of long lists of items
self.setStyleSheet("QComboBox {combobox-popup: 0;}")
return return
def wheelEvent(self, event: QWheelEvent) -> None: def wheelEvent(self, event: QWheelEvent) -> None:
"""Only capture the mouse wheel if the widget has focus."""
if self.hasFocus(): if self.hasFocus():
super().wheelEvent(event) super().wheelEvent(event)
else: else:
+6 -1
View File
@@ -25,14 +25,19 @@ from __future__ import annotations
import logging import logging
from typing import TYPE_CHECKING
from PyQt6.QtCore import pyqtSignal, pyqtSlot from PyQt6.QtCore import pyqtSignal, pyqtSlot
from PyQt6.QtGui import QPalette from PyQt6.QtGui import QPalette
from PyQt6.QtWidgets import QComboBox, QWidget from PyQt6.QtWidgets import QComboBox
from novelwriter import SHARED from novelwriter import SHARED
from novelwriter.constants import nwLabels from novelwriter.constants import nwLabels
from novelwriter.enum import nwItemClass from novelwriter.enum import nwItemClass
if TYPE_CHECKING:
from PyQt6.QtWidgets import QWidget
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
+1
View File
@@ -126,6 +126,7 @@ QtHeaderFixed = QHeaderView.ResizeMode.Fixed
# Scroll Bar Policy # Scroll Bar Policy
QtScrollAlwaysOn = Qt.ScrollBarPolicy.ScrollBarAlwaysOn
QtScrollAlwaysOff = Qt.ScrollBarPolicy.ScrollBarAlwaysOff QtScrollAlwaysOff = Qt.ScrollBarPolicy.ScrollBarAlwaysOff
QtScrollAsNeeded = Qt.ScrollBarPolicy.ScrollBarAsNeeded QtScrollAsNeeded = Qt.ScrollBarPolicy.ScrollBarAsNeeded