Modify the style to show a scroll bar for combo boxes
This commit is contained in:
@@ -117,12 +117,19 @@ class NTreeView(QTreeView):
|
||||
|
||||
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)
|
||||
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
|
||||
|
||||
def wheelEvent(self, event: QWheelEvent) -> None:
|
||||
"""Only capture the mouse wheel if the widget has focus."""
|
||||
if self.hasFocus():
|
||||
super().wheelEvent(event)
|
||||
else:
|
||||
|
||||
@@ -25,14 +25,19 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from PyQt6.QtCore import pyqtSignal, pyqtSlot
|
||||
from PyQt6.QtGui import QPalette
|
||||
from PyQt6.QtWidgets import QComboBox, QWidget
|
||||
from PyQt6.QtWidgets import QComboBox
|
||||
|
||||
from novelwriter import SHARED
|
||||
from novelwriter.constants import nwLabels
|
||||
from novelwriter.enum import nwItemClass
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from PyQt6.QtWidgets import QWidget
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user