Files
novelWriter/novelwriter/extensions/simpleprogress.py
T
2023-06-09 21:07:46 +02:00

55 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
novelWriter Custom Widget: Progress Simple
============================================
File History:
Created: 2023-06-09 [2.1b1]
This file is a part of novelWriter
Copyright 20182023, Veronica Berglyd Olsen
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from __future__ import annotations
from math import ceil
from PyQt5.QtGui import QPaintEvent, QPainter
from PyQt5.QtWidgets import QProgressBar, QWidget
class NProgressSimple(QProgressBar):
"""Extension: Simple Progress Widget
A custom widget that paints a plain bar with no other styling.
"""
def __init__(self, parent: QWidget):
super().__init__(parent=parent)
return
def paintEvent(self, event: QPaintEvent):
"""Custom painter for the progress bar."""
if self.value() == 0:
return
progress = ceil(self.width()*float(self.value())/self.maximum())
qPaint = QPainter(self)
qPaint.setRenderHint(QPainter.Antialiasing, True)
qPaint.setPen(self.palette().highlight().color())
qPaint.setBrush(self.palette().highlight())
qPaint.drawRect(0, 0, progress, self.height())
return
# END Class NProgressSimple