提交 35d14c98 编写于 作者: 之一Yo's avatar 之一Yo

调整单行编辑框底部边框样式,添加富文本框

上级 9b8d43aa
......@@ -273,7 +273,7 @@
<message>
<location filename="../../view/main_window.py" line="189"/>
<source>Text</source>
<translation type="unfinished"></translation>
<translation>文本</translation>
</message>
</context>
<context>
......@@ -688,52 +688,52 @@
<message>
<location filename="../../view/status_info_interface.py" line="113"/>
<source>Top right</source>
<translation type="unfinished"></translation>
<translation>右上角</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="114"/>
<source>Top</source>
<translation type="unfinished"></translation>
<translation>頂部居中</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="115"/>
<source>Top left</source>
<translation type="unfinished"></translation>
<translation>左上角</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="116"/>
<source>Bottom right</source>
<translation type="unfinished"></translation>
<translation>右下角</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="117"/>
<source>Bottom</source>
<translation type="unfinished"></translation>
<translation>底部居中</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="118"/>
<source>Bottom left</source>
<translation type="unfinished"></translation>
<translation>左下角</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="201"/>
<source>Lesson 1</source>
<translation type="unfinished">Lesson 1</translation>
<translation>Lesson 1</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="201"/>
<source>Don&apos;t have any strange expectations of me.</source>
<translation type="unfinished"></translation>
<translation>別對我抱有什麼奇怪的期待</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="212"/>
<source>Lesson 2</source>
<translation type="unfinished">Lesson 2</translation>
<translation>Lesson 2</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="212"/>
<source>Don&apos;t let your muscles notice.</source>
<translation type="unfinished"></translation>
<translation>不要讓肌肉察覺</translation>
</message>
</context>
<context>
......@@ -741,37 +741,42 @@
<message>
<location filename="../../view/text_interface.py" line="23"/>
<source>ko no dio da</source>
<translation type="unfinished"></translation>
<translation></translation>
</message>
<message>
<location filename="../../view/text_interface.py" line="25"/>
<source>A LineEdit with a clear button</source>
<translation type="unfinished"></translation>
<translation>帶清空按鈕的 LineEdit</translation>
</message>
<message>
<location filename="../../view/text_interface.py" line="39"/>
<source>A DoubleSpinBox with a spin button</source>
<translation type="unfinished"></translation>
<translation>帶調節按鈕的 DoubleSpinBox</translation>
</message>
<message>
<location filename="../../view/text_interface.py" line="46"/>
<source>A DateEdit with a spin button</source>
<translation type="unfinished"></translation>
<translation>帶調節按鈕的 DateEdit</translation>
</message>
<message>
<location filename="../../view/text_interface.py" line="53"/>
<source>A TimeEdit with a spin button</source>
<translation type="unfinished"></translation>
<translation>帶調節按鈕的 TimeEdit</translation>
</message>
<message>
<location filename="../../view/text_interface.py" line="60"/>
<source>A DateTimeEdit with a spin button</source>
<translation type="unfinished"></translation>
<translation>帶調節按鈕的 DateTimeEdit</translation>
</message>
<message>
<location filename="../../view/text_interface.py" line="32"/>
<source>A SpinBox with a spin button</source>
<translation type="unfinished"></translation>
<translation>帶調節按鈕的 SpinBox</translation>
</message>
<message>
<location filename="../../view/text_interface.py" line="71"/>
<source>A simple TextEdit</source>
<translation>富文本框</translation>
</message>
</context>
<context>
......@@ -837,7 +842,7 @@
<message>
<location filename="../../common/translator.py" line="16"/>
<source>Text</source>
<translation type="unfinished"></translation>
<translation>文本</translation>
</message>
</context>
</TS>
</TS>
\ No newline at end of file
......@@ -773,6 +773,11 @@
<source>A SpinBox with a spin button</source>
<translation>带调节按钮的 SpinBox</translation>
</message>
<message>
<location filename="../../view/text_interface.py" line="71"/>
<source>A simple TextEdit</source>
<translation>富文本框</translation>
</message>
</context>
<context>
<name>ToolBar</name>
......
......@@ -277,10 +277,18 @@ class HomeInterface(ScrollArea):
)
textView.addSampleCard(
icon="app/resource/images/controls/NumberBox.png",
title="NumberBox",
title="SpinBox",
content=self.tr(
"A text control used for numeric input and evaluation of algebraic equations."),
routeKey="textInterface",
index=1
)
textView.addSampleCard(
icon="app/resource/images/controls/RichEditBox.png",
title="TextEdit",
content=self.tr(
"A rich text editing control that supports formatted text, hyperlinks, and other rich content."),
routeKey="textInterface",
index=6
)
self.vBoxLayout.addWidget(textView)
......@@ -2,7 +2,7 @@
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap, QColor
from PyQt5.QtWidgets import QWidget, QHBoxLayout
from qfluentwidgets import LineEdit, SpinBox, DoubleSpinBox, TimeEdit, DateTimeEdit, DateEdit
from qfluentwidgets import LineEdit, SpinBox, DoubleSpinBox, TimeEdit, DateTimeEdit, DateEdit, TextEdit
from .gallery_interface import GalleryInterface
from ..common.translator import Translator
......@@ -62,3 +62,15 @@ class TextInterface(GalleryInterface):
widget=DateTimeEdit(self),
sourcePath='https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/spin_box/demo.py'
)
# text edit
textEdit = TextEdit(self)
textEdit.setMarkdown(
"## Steel Ball Run \n * Johnny Joestar 🦄 \n * Gyro Zeppeli 🐴 ")
textEdit.setFixedHeight(150)
self.addExampleCard(
title=self.tr("A simple TextEdit"),
widget=textEdit,
sourcePath='https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/line_edit/demo.py',
stretch=1
)
......@@ -3,7 +3,7 @@ import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QWidget
from qfluentwidgets import LineEdit, PushButton
from qfluentwidgets import LineEdit, PushButton, TextEdit
class Demo(QWidget):
......@@ -12,9 +12,13 @@ class Demo(QWidget):
super().__init__()
self.lineEdit = LineEdit('', self)
self.button = PushButton('按钮', self)
self.textEdit = TextEdit(self)
self.resize(500, 500)
self.lineEdit.move(110, 220)
self.button.move(320, 220)
self.textEdit.move(110, 200)
self.lineEdit.move(110, 50)
self.button.move(320, 52)
self.lineEdit.resize(200, 33)
self.lineEdit.setClearButtonEnabled(True)
......
......@@ -12,7 +12,7 @@ Examples are available at https://github.com/zhiyiYo/PyQt-Fluent-Widgets/tree/ma
:license: GPLv3, see LICENSE for more details.
"""
__version__ = "0.5.2"
__version__ = "0.5.3"
from .components import *
from .common import *
......
......@@ -6,6 +6,7 @@ PushButton, ToolButton {
color: white;
font: 14px 'Segoe UI', 'Microsoft YaHei';
padding: 5px 12px 6px 12px;
outline: none;
}
ToolButton {
......
......@@ -125,6 +125,7 @@ QScrollBar::sub-page:vertical {
color: white;
font: 14px 'Segoe UI', 'Microsoft YaHei';
padding: 5px 9px 6px 9px;
outline: none;
}
#cancelButton:hover {
......
QLineEdit {
LineEdit, TextEdit {
background-color: rgb(55, 55, 55);
border: 1px solid rgb(58, 58, 58);
border-bottom: 1px solid rgb(159, 159, 159);
......@@ -10,21 +10,25 @@ QLineEdit {
selection-color: black;
}
QLineEdit:hover {
TextEdit {
padding: 0px 0px 0px 10px;
}
LineEdit:hover, TextEdit:hover {
background-color: rgb(60, 60, 60);
}
QLineEdit:!focus {
LineEdit:!focus, TextEdit:!focus {
background-color: rgb(55, 55, 55);
border-bottom: 1px solid rgb(159, 159, 159);
}
QLineEdit:focus {
LineEdit:focus, TextEdit:focus {
border-bottom: 1px solid --ThemeColorPrimary;
background-color: rgb(34, 34, 34);
}
QLineEdit:disabled {
LineEdit:disabled, TextEdit:disabled {
color: rgba(255, 255, 255, 150);
background-color: rgb(59, 59, 59);
border: 1px solid rgb(73, 73, 73);
......@@ -42,4 +46,50 @@ QLineEdit:disabled {
#clearButton:pressed {
background-color: rgba(255, 255, 255, 6);
}
QScrollBar {
background: transparent;
width: 4px;
margin-top: 12px;
margin-bottom: 0;
padding-right: 2px;
}
QScrollBar:horizontal {
background: transparent;
height: 4px;
margin-left: 12px;
margin-right: 12px;
padding-bottom: 2px;
}
QScrollBar::sub-line {
background: transparent;
}
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
}
QScrollBar::handle:vertical {
min-height: 32px;
}
QScrollBar::handle:horizontal {
min-width: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical,
QScrollBar::add-page:horizontal,
QScrollBar::sub-page:horizontal {
background: none;
}
\ No newline at end of file
......@@ -6,6 +6,7 @@ PushButton, ToolButton {
border-radius: 5px;
font: 14px 'Segoe UI', 'Microsoft YaHei';
padding: 5px 12px 6px 12px;
outline: none;
}
ToolButton {
......
......@@ -122,6 +122,7 @@ QScrollBar::sub-page:vertical {
border-radius: 5px;
font: 14px 'Segoe UI', 'Microsoft YaHei';
padding: 5px 9px 6px 9px;
outline: none;
}
#cancelButton:hover {
......
QLineEdit {
LineEdit, TextEdit {
color: black;
background-color: white;
border: 1px solid rgba(0, 0, 0, 13);
......@@ -9,23 +9,27 @@ QLineEdit {
selection-background-color: --ThemeColorLight1;
}
QLineEdit:hover {
TextEdit {
padding: 0px 0px 0px 10px;
}
LineEdit:hover, TextEdit:hover {
background-color: rgb(252, 252, 252);
border: 1px solid rgba(0, 0, 0, 13);
border-bottom: 1px solid rgba(0, 0, 0, 100);
}
QLineEdit:!focus {
LineEdit:!focus, TextEdit:!focus {
background-color: white;
border-bottom: 1px solid rgba(0, 0, 0, 100);
}
QLineEdit:focus {
LineEdit:focus, TextEdit:focus {
border-bottom: 1px solid --ThemeColorPrimary;
background-color: white;
}
QLineEdit:disabled {
LineEdit:disabled, TextEdit:disabled {
color: rgba(0, 0, 0, 150);
background-color: rgb(252, 252, 252);
border: 1px solid rgb(237, 237, 237);
......@@ -43,4 +47,50 @@ QLineEdit:disabled {
#clearButton:pressed {
background-color: rgba(0, 0, 0, 6);
}
QScrollBar:vertical {
background: transparent;
width: 4px;
margin-top: 12px;
margin-bottom: 12px;
padding-right: 2px;
}
QScrollBar:horizontal {
background: transparent;
height: 4px;
margin-left: 12px;
margin-right: 12px;
padding-bottom: 2px;
}
QScrollBar::sub-line {
background: transparent;
}
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
}
QScrollBar::handle:vertical {
min-height: 32px;
}
QScrollBar::handle:horizontal {
min-width: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical,
QScrollBar::add-page:horizontal,
QScrollBar::sub-page:horizontal {
background: none;
}
\ No newline at end of file
此差异已折叠。
from .button import PrimaryPushButton, PushButton, RadioButton, HyperlinkButton, ToolButton
from .check_box import CheckBox
from .combo_box import ComboBox
from .line_edit import LineEdit
from .line_edit import LineEdit, TextEdit
from .icon_widget import IconWidget
from .label import PixmapLabel
from .menu import DWMMenu, LineEditMenu, RoundMenu
......
# coding: utf-8
from PyQt5.QtCore import QSize, Qt, QRectF
from PyQt5.QtGui import QPainter
from PyQt5.QtWidgets import QLineEdit, QToolButton
from PyQt5.QtCore import QSize, Qt, QRectF, QEvent
from PyQt5.QtGui import QPainter, QPainterPath
from PyQt5.QtWidgets import QLineEdit, QToolButton, QTextEdit
from ...common.style_sheet import setStyleSheet
from ...common.style_sheet import setStyleSheet, themeColor
from ...common.icon import writeSvg, isDarkTheme, drawSvgIcon
from ...common.icon import FluentIcon as FIF
from .menu import LineEditMenu
from ...common.smooth_scroll import SmoothMode, SmoothScroll
from .menu import LineEditMenu, TextEditMenu
class ClearButton(QToolButton):
......@@ -23,7 +24,8 @@ class ClearButton(QToolButton):
def paintEvent(self, e):
super().paintEvent(e)
painter = QPainter(self)
painter.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
painter.setRenderHints(QPainter.Antialiasing |
QPainter.SmoothPixmapTransform)
if isDarkTheme():
FIF.CLOSE.render(painter, QRectF(9.5, 7, 10, 10))
else:
......@@ -76,3 +78,43 @@ class LineEdit(QLineEdit):
def resizeEvent(self, e):
self.clearButton.move(self.width() - 33, 4)
def paintEvent(self, e):
super().paintEvent(e)
if not self.hasFocus():
return
painter = QPainter(self)
painter.setRenderHints(QPainter.Antialiasing)
painter.setPen(Qt.NoPen)
path = QPainterPath()
w, h = self.width() - 2, self.height()
path.addRoundedRect(QRectF(1, h-12, w, 12), 6, 6)
rectPath = QPainterPath()
rectPath.addRect(1, h-12, w, 9.5)
path = path.subtracted(rectPath)
painter.fillPath(path, themeColor())
class TextEdit(QTextEdit):
""" Text edit """
def __init__(self, parent=None):
super().__init__(parent=parent)
self.verticalSmoothScroll = SmoothScroll(self, Qt.Vertical)
self.horizonSmoothScroll = SmoothScroll(self, Qt.Horizontal)
setStyleSheet(self, 'line_edit')
def contextMenuEvent(self, e):
menu = TextEditMenu(self)
menu.exec_(e.globalPos())
def wheelEvent(self, e):
if e.modifiers() == Qt.NoModifier:
self.verticalSmoothScroll.wheelEvent(e)
else:
self.horizonSmoothScroll.wheelEvent(e)
......@@ -2,10 +2,10 @@
from qframelesswindow import WindowEffect
from PyQt5.QtCore import (QEasingCurve, QEvent, QPropertyAnimation, QRect,
Qt, QSize, QRectF, pyqtSignal, QPoint, QTimer)
from PyQt5.QtGui import QIcon, QColor, QPainter, QPen, QPixmap, QRegion, QCursor
from PyQt5.QtGui import QIcon, QColor, QPainter, QPen, QPixmap, QRegion, QCursor, QTextCursor
from PyQt5.QtWidgets import (QAction, QApplication, QMenu, QProxyStyle, QStyle,
QGraphicsDropShadowEffect, QListWidget, QWidget, QHBoxLayout,
QListWidgetItem)
QListWidgetItem, QLineEdit, QTextEdit)
from ...common.smooth_scroll import SmoothScroll
from ...common.icon import FluentIcon as FIF
......@@ -52,7 +52,6 @@ class DWMMenu(QMenu):
return QMenu.event(self, e)
class MenuSeparator(QWidget):
""" Menu separator """
......@@ -514,8 +513,9 @@ class RoundMenu(QWidget):
# get the rect of menu item
margin = view.viewportMargins()
rect = view.visualItemRect(self.menuItem).translated(view.mapToGlobal(QPoint()))
rect= rect.translated(margin.left(), margin.top()+2)
rect = view.visualItemRect(self.menuItem).translated(
view.mapToGlobal(QPoint()))
rect = rect.translated(margin.left(), margin.top()+2)
if self.parentMenu.geometry().contains(pos) and not rect.contains(pos) and \
not self.geometry().contains(pos):
view.clearSelection()
......@@ -569,7 +569,8 @@ class RoundMenu(QWidget):
rect = QApplication.screenAt(QCursor.pos()).availableGeometry()
w, h = self.width() + 5, self.height() + 5
pos.setX(min(pos.x() - self.layout().contentsMargins().left(), rect.right() - w))
pos.setX(
min(pos.x() - self.layout().contentsMargins().left(), rect.right() - w))
pos.setY(min(pos.y() - 4, rect.bottom() - h))
if ani:
......@@ -610,17 +611,8 @@ class RoundMenu(QWidget):
self.exec(pos, ani)
class LineEditMenu(RoundMenu):
""" Line edit menu """
def __init__(self, parent):
super().__init__("", parent)
self.animation = QPropertyAnimation(self, b"geometry")
self.animation.setDuration(300)
self.animation.setEasingCurve(QEasingCurve.OutQuad)
self.setProperty("selectAll", bool(self.parent().text()))
self.selectionStart = parent.selectionStart()
self.selectionLength = parent.selectionLength()
class EditMenu(RoundMenu):
""" Edit menu """
def createActions(self):
self.cutAct = QAction(
......@@ -657,30 +649,32 @@ class LineEditMenu(RoundMenu):
shortcut="Ctrl+A",
triggered=self.parent().selectAll
)
self.action_list = [self.cutAct, self.copyAct,
self.pasteAct, self.cancelAct, self.selectAllAct]
self.action_list = [
self.cutAct, self.copyAct,
self.pasteAct, self.cancelAct, self.selectAllAct
]
def _onItemClicked(self, item):
if self.selectionLength:
self.parent().setSelection(self.selectionStart, self.selectionLength)
def _parentText(self):
raise NotImplementedError
super()._onItemClicked(item)
def _parentSelectedText(self):
raise NotImplementedError
def exec(self, pos, ani=True):
self.clear()
self.createActions()
if QApplication.clipboard().mimeData().hasText():
if self.parent().text():
if self.parent().selectedText():
if self._parentText():
if self._parentSelectedText():
self.addActions(self.action_list)
else:
self.addActions(self.action_list[2:])
else:
self.addAction(self.pasteAct)
else:
if self.parent().text():
if self.parent().selectedText():
if self._parentText():
if self._parentSelectedText():
self.addActions(
self.action_list[:2] + self.action_list[3:])
else:
......@@ -689,3 +683,50 @@ class LineEditMenu(RoundMenu):
return
super().exec(pos, ani)
class LineEditMenu(EditMenu):
""" Line edit menu """
def __init__(self, parent: QLineEdit):
super().__init__("", parent)
self.selectionStart = parent.selectionStart()
self.selectionLength = parent.selectionLength()
def _onItemClicked(self, item):
if self.selectionStart >= 0:
self.parent().setSelection(self.selectionStart, self.selectionLength)
super()._onItemClicked(item)
def _parentText(self):
return self.parent().text()
def _parentSelectedText(self):
return self.parent().selectedText()
class TextEditMenu(EditMenu):
""" Text edit menu """
def __init__(self, parent: QTextEdit):
super().__init__("", parent)
cursor = parent.textCursor()
self.selectionStart = cursor.selectionStart()
self.selectionLength = cursor.selectionEnd() - self.selectionStart + 1
def _parentText(self):
return self.parent().toPlainText()
def _parentSelectedText(self):
return self.parent().textCursor().selectedText()
def _onItemClicked(self, item):
if self.selectionStart >= 0:
cursor = self.parent().textCursor()
cursor.setPosition(self.selectionStart)
cursor.movePosition(
QTextCursor.Right, QTextCursor.KeepAnchor, self.selectionLength)
super()._onItemClicked(item)
......@@ -2,11 +2,11 @@
from enum import Enum
from PyQt5.QtCore import Qt, QSize, QRectF
from PyQt5.QtGui import QPainter, QTextCursor
from PyQt5.QtGui import QPainter, QPainterPath
from PyQt5.QtWidgets import (QSpinBox, QDoubleSpinBox, QToolButton, QHBoxLayout,
QDateEdit, QDateTimeEdit, QTimeEdit)
QDateEdit, QDateTimeEdit, QTimeEdit, QLineEdit, QAbstractSpinBox)
from ...common.style_sheet import setStyleSheet
from ...common.style_sheet import setStyleSheet, themeColor
from ...common.icon import FluentIconBase, Theme, getIconColor
from ...components.widgets import LineEditMenu
......@@ -77,6 +77,24 @@ class Ui_SpinBox:
menu = LineEditMenu(self.lineEdit())
menu.exec_(self.mapToGlobal(pos))
def _drawBorderBottom(self):
if not self.hasFocus():
return
painter = QPainter(self)
painter.setRenderHints(QPainter.Antialiasing)
painter.setPen(Qt.NoPen)
path = QPainterPath()
w, h = self.width() - 2, self.height()
path.addRoundedRect(QRectF(1, h-12, w, 12), 6, 6)
rectPath = QPainterPath()
rectPath.addRect(1, h-12, w, 9.5)
path = path.subtracted(rectPath)
painter.fillPath(path, themeColor())
class SpinBox(QSpinBox, Ui_SpinBox):
""" Spin box """
......@@ -85,6 +103,10 @@ class SpinBox(QSpinBox, Ui_SpinBox):
super().__init__(parent=parent)
self._setUpUi()
def paintEvent(self, e):
super().paintEvent(e)
self._drawBorderBottom()
class DoubleSpinBox(QDoubleSpinBox, Ui_SpinBox):
""" Double spin box """
......@@ -93,6 +115,10 @@ class DoubleSpinBox(QDoubleSpinBox, Ui_SpinBox):
super().__init__(parent)
self._setUpUi()
def paintEvent(self, e):
super().paintEvent(e)
self._drawBorderBottom()
class TimeEdit(QTimeEdit, Ui_SpinBox):
""" Time edit """
......@@ -101,6 +127,10 @@ class TimeEdit(QTimeEdit, Ui_SpinBox):
super().__init__(parent)
self._setUpUi()
def paintEvent(self, e):
super().paintEvent(e)
self._drawBorderBottom()
class DateTimeEdit(QDateTimeEdit, Ui_SpinBox):
""" Date time edit """
......@@ -109,6 +139,10 @@ class DateTimeEdit(QDateTimeEdit, Ui_SpinBox):
super().__init__(parent)
self._setUpUi()
def paintEvent(self, e):
super().paintEvent(e)
self._drawBorderBottom()
class DateEdit(QDateEdit, Ui_SpinBox):
""" Date edit """
......@@ -117,3 +151,7 @@ class DateEdit(QDateEdit, Ui_SpinBox):
super().__init__(parent)
self._setUpUi()
def paintEvent(self, e):
super().paintEvent(e)
self._drawBorderBottom()
......@@ -6,7 +6,7 @@ with open('README.md', encoding='utf-8') as f:
setuptools.setup(
name="PyQt-Fluent-Widgets",
version="0.5.2",
version="0.5.3",
keywords="pyqt fluent widgets",
author="zhiyiYo",
author_email="shokokawaii@outlook.com",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册