This commit is contained in:
恍兮惚兮 2024-06-21 19:17:21 +08:00
parent 5fa8f1a8a6
commit f6014cf9a8
6 changed files with 40 additions and 35 deletions

View File

@ -24,15 +24,19 @@ if __name__ == "__main__":
from qtsymbols import *
if isqt5:
QApplication.addLibraryPath(
"./LunaTranslator/runtime/PyQt5/Qt5/plugins"
) # 中文字符下不能自动加载
# 中文字符下不能自动加载
QApplication.addLibraryPath("./LunaTranslator/runtime/PyQt5/Qt5/plugins")
QApplication.setAttribute(Qt.ApplicationAttribute.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.ApplicationAttribute.AA_UseHighDpiPixmaps)
if gobject.testuseqwebengine():
if gobject.testuseqwebengine():
# maybe use qwebengine
QApplication.setAttribute(Qt.ApplicationAttribute.AA_ShareOpenGLContexts)
if not isqt5:
# devtool
QApplication.setAttribute(
Qt.ApplicationAttribute.AA_ShareOpenGLContexts
) # maybe use qwebengine
Qt.ApplicationAttribute.AA_DontCreateNativeWidgetSiblings
)
QApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough

View File

@ -266,8 +266,8 @@ class MySwitch(QWidget):
x + self.sizeHint().height() // 2 + offset,
y + self.sizeHint().height() // 2,
),
self.sizeHint().height() * 0.35,
self.sizeHint().height() * 0.35,
int(self.sizeHint().height() * 0.35),
int(self.sizeHint().height() * 0.35),
)
def mouseReleaseEvent(self, event) -> None:
@ -475,12 +475,9 @@ class resizableframeless(saveposwindow):
super().resizeEvent(e)
def mousePressEvent(self, event: QMouseEvent):
if isqt5:
gpos = event.globalPos()
else:
gpos = event.globalPosition().toPoint()
if event.button() != Qt.MouseButton.LeftButton:
return
gpos = QCursor.pos()
self.startxp = gpos - self.pos()
self.starty = gpos.y()
self.startx = gpos.x()
@ -513,11 +510,7 @@ class resizableframeless(saveposwindow):
def mouseMoveEvent(self, event):
pos = event.pos()
if isqt5:
gpos = event.globalPos()
else:
gpos = event.globalPosition().toPoint()
gpos = QCursor.pos()
if isinrect(pos, self._corner_youxia):
self.setCursor(Qt.CursorShape.SizeFDiagCursor)
elif isinrect(pos, self._corner_zuoshang):
@ -1059,8 +1052,10 @@ class QWebWrap(abstractwebview):
def __init__(self, p=None) -> None:
super().__init__(p)
from PyQt5.QtWebEngineWidgets import QWebEngineView
if isqt5:
from PyQt5.QtWebEngineWidgets import QWebEngineView
else:
from PyQt6.QtWebEngineWidgets import QWebEngineView
self.internal = QWebEngineView(self)
# self.internal.page().urlChanged.connect(
# lambda qurl: self.on_load.emit(qurl.url())

View File

@ -4,6 +4,9 @@ try:
from PyQt5.QtGui import QIconEngine,QIntValidator,QStandardItem,QStandardItemModel,QImageWriter,QIcon,QTextCharFormat,QTextBlockFormat,QResizeEvent,QTextCursor,QFontMetricsF,QMouseEvent,QImage,QPainter,QRegion,QCloseEvent,QFontDatabase,QKeySequence,QPixmap,QCursor,QColor,QFont,QPen,QPainterPath,QBrush,QFontMetrics,QShowEvent,QWheelEvent,QPaintEvent
from PyQt5.QtCore import QObject,pyqtSignal,Qt,QSize,QByteArray,QBuffer,QPointF,QPoint,QRect,QEvent,QModelIndex,QTimer,QRectF,QVariantAnimation,QUrl
isqt5 = True
class LineHeightTypes:
LineDistanceHeight=QTextBlockFormat.LineHeightTypes.LineDistanceHeight
FixedHeight=QTextBlockFormat.LineHeightTypes.FixedHeight
except:
#from traceback import print_exc
#print_exc()
@ -11,4 +14,8 @@ except:
from PyQt6.QtWidgets import QFrame,QListView,QCheckBox,QAbstractItemView,QTextEdit,QTableView,QHeaderView,QColorDialog,QSpinBox,QDoubleSpinBox,QComboBox,QDialogButtonBox,QMainWindow,QMessageBox,QDialog,QGridLayout,QTextBrowser,QGraphicsDropShadowEffect,QWidget,QSizePolicy,QScrollArea,QApplication,QPushButton,QSystemTrayIcon,QPlainTextEdit,QMenu,QFileDialog,QKeySequenceEdit,QLabel,QSpacerItem,QWidgetItem,QLayout,QTextBrowser,QLineEdit,QFormLayout,QSizePolicy,QTabWidget,QTabBar,QSplitter,QListWidget,QListWidgetItem,QHBoxLayout,QVBoxLayout,QSizeGrip,QFontComboBox,QProgressBar,QRadioButton,QButtonGroup,QSlider,QToolTip,QGroupBox
from PyQt6.QtGui import QIconEngine,QIntValidator,QAction,QStandardItem,QStandardItemModel,QImageWriter,QIcon,QTextCharFormat,QTextBlockFormat,QResizeEvent,QTextCursor,QFontMetricsF,QMouseEvent,QImage,QPainter,QRegion,QCloseEvent,QFontDatabase,QKeySequence,QPixmap,QCursor,QColor,QFont,QPen,QPainterPath,QBrush,QFontMetrics,QShowEvent,QWheelEvent,QPaintEvent
from PyQt6.QtCore import QObject,pyqtSignal,Qt,QSize,QByteArray,QBuffer,QPointF,QPoint,QRect,QEvent,QModelIndex,QTimer,QRectF,QVariantAnimation,QUrl
isqt5 = False
isqt5 = False
class LineHeightTypes:
LineDistanceHeight=QTextBlockFormat.LineHeightTypes.LineDistanceHeight.value
FixedHeight=QTextBlockFormat.LineHeightTypes.FixedHeight.value

View File

@ -1,4 +1,3 @@
from PyQt5.QtWidgets import QWidget
from qtsymbols import *
from myutils.config import globalconfig
from rendertext.somefunctions import dataget
@ -263,11 +262,7 @@ class TextBrowser(QWidget, dataget):
for i in range(self.blockcount, self.textbrowser.document().blockCount()):
b = self.textbrowser.document().findBlockByNumber(i)
tf = b.blockFormat()
if isqt5:
lht = QTextBlockFormat.LineHeightTypes.LineDistanceHeight
else:
lht = 4
tf.setLineHeight(fh, lht)
tf.setLineHeight(fh, LineHeightTypes.LineDistanceHeight)
self.textcursor.setPosition(b.position())
self.textcursor.setBlockFormat(tf)
self.textbrowser.setTextCursor(self.textcursor)
@ -552,11 +547,7 @@ class TextBrowser(QWidget, dataget):
b = self.textbrowser.document().findBlockByNumber(i)
tf = b.blockFormat()
if isqt5:
lht = QTextBlockFormat.LineHeightTypes.FixedHeight
else:
lht = 2
tf.setLineHeight(fasall + fha, lht)
tf.setLineHeight(fasall + fha, LineHeightTypes.FixedHeight)
self.textcursor.setPosition(b.position())
self.textcursor.setBlockFormat(tf)
self.textbrowser.setTextCursor(self.textcursor)

View File

@ -1,4 +1,3 @@
from PyQt5.QtWidgets import QWidget
from qtsymbols import *
from rendertext.somefunctions import dataget
import gobject, uuid, json, os, functools
@ -49,10 +48,17 @@ class TextBrowser(QWidget, dataget):
self._qweb_query_word()
def _qwmenu(self, pos):
from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineView
if isqt5:
from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineView
web_menu = self.webivewwidget.internal.page().createStandardContextMenu()
else:
from PyQt6.QtWebEngineWidgets import QWebEngineView
from PyQt6.QtWebEngineCore import QWebEnginePage
web_menu = self.webivewwidget.internal.createStandardContextMenu()
loadinspector = QAction("Inspect")
web_menu = self.webivewwidget.internal.page().createStandardContextMenu()
if (
self.webivewwidget.internal.page().action(
QWebEnginePage.WebAction.InspectElement
@ -60,7 +66,7 @@ class TextBrowser(QWidget, dataget):
not in web_menu.actions()
):
web_menu.addAction(loadinspector)
action = web_menu.exec_(self.webivewwidget.mapToGlobal(pos))
action = web_menu.exec(self.webivewwidget.mapToGlobal(pos))
if action == loadinspector:

View File

@ -0,0 +1,2 @@
python.exe -B LunaTranslator\LunaTranslator_main.py test
pause