Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Qt6 #131

Merged
merged 2 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tabulous/_qt/_preference/_shared.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from qtpy import QtWidgets as QtW, QtGui, QtCore
from tabulous._qt._qt_const import foreground_color_role


class QTitleLabel(QtW.QLabel):
Expand All @@ -13,7 +14,7 @@ def __init__(self, text: str, size: int) -> None:

def paintEvent(self, a0: QtGui.QPaintEvent) -> None:
painter = QtGui.QPainter(self)
color = self.palette().color(QtGui.QPalette.ColorRole.Foreground)
color = foreground_color_role(self.palette())
painter.setPen(QtGui.QPen(color, 1))
bottom_left = self.rect().bottomLeft()
bottom_right = QtCore.QPoint(bottom_left.x() + 300, bottom_left.y())
Expand Down
20 changes: 12 additions & 8 deletions tabulous/_qt/_preference/_theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,24 @@ def paintEvent(self, a0: QtGui.QPaintEvent) -> None:
painter = QtGui.QPainter(self)
geo = self.rect()

grad = QtGui.QLinearGradient(geo.topLeft(), geo.bottomRight())
grad = QtGui.QLinearGradient(
QtCore.QPointF(geo.topLeft()), QtCore.QPointF(geo.bottomRight())
)
grad.setColorAt(0, QtGui.QColor(self._style_theme.background0))
grad.setColorAt(1, QtGui.QColor(self._style_theme.background1))
path = QtGui.QPainterPath(geo.topLeft())
path.lineTo(geo.topRight())
path.lineTo(geo.bottomLeft())
path = QtGui.QPainterPath(QtCore.QPointF(geo.topLeft()))
path.lineTo(QtCore.QPointF(geo.topRight()))
path.lineTo(QtCore.QPointF(geo.bottomLeft()))
painter.fillPath(path, grad)

grad = QtGui.QLinearGradient(geo.topLeft(), geo.bottomRight())
grad = QtGui.QLinearGradient(
QtCore.QPointF(geo.topLeft()), QtCore.QPointF(geo.bottomRight())
)
grad.setColorAt(0, QtGui.QColor(self._style_theme.highlight0))
grad.setColorAt(1, QtGui.QColor(self._style_theme.highlight1))
path = QtGui.QPainterPath(geo.topRight())
path.lineTo(geo.bottomLeft())
path.lineTo(geo.bottomRight())
path = QtGui.QPainterPath(QtCore.QPointF(geo.topRight()))
path.lineTo(QtCore.QPointF(geo.bottomLeft()))
path.lineTo(QtCore.QPointF(geo.bottomRight()))
painter.fillPath(path, grad)

if self._checked:
Expand Down
21 changes: 21 additions & 0 deletions tabulous/_qt/_qt_const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
from pathlib import Path
from qtpy import QtGui, QT6

# Monospace font
if sys.platform == "win32":
Expand All @@ -10,3 +11,23 @@
MonospaceFontFamily = "Monospace"

ICON_DIR = Path(__file__).parent / "_icons"

if QT6:

def foreground_color_role(qpalette: QtGui.QPalette) -> QtGui.QColor:
return qpalette.color(
QtGui.QPalette.ColorGroup.Normal, QtGui.QPalette.ColorRole.Text
)

def background_color_role(qpalette: QtGui.QPalette) -> QtGui.QColor:
return qpalette.color(
QtGui.QPalette.ColorGroup.Normal, QtGui.QPalette.ColorRole.Base
)

else:

def foreground_color_role(qpalette: QtGui.QPalette) -> QtGui.QColor:
return qpalette.color(QtGui.QPalette.ColorRole.Foreground)

def background_color_role(qpalette: QtGui.QPalette) -> QtGui.QColor:
return qpalette.color(QtGui.QPalette.ColorRole.Background)
3 changes: 2 additions & 1 deletion tabulous/_qt/_table/_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from contextlib import contextmanager
from tabulous._utils import get_config
from tabulous._range import MultiRectRange, RectRange
from tabulous._qt._qt_const import background_color_role

from qtpy import QtCore, QtWidgets as QtW, QtGui

Expand Down Expand Up @@ -123,7 +124,7 @@ def get_brush(self, size: QtCore.QSize, time: float, bg) -> QtGui.QBrush:
qtable = self._parent.parent()
is_qvariant = not isinstance(bg, QtGui.QColor)
if is_qvariant:
bg = qtable.palette().color(QtGui.QPalette.ColorRole.Background)
bg = background_color_role(qtable.palette())
col = qtable._qtable_view.selectionColor
length = max(size.width(), size.height())
dh = 4 / length
Expand Down
2 changes: 2 additions & 0 deletions tabulous/_qt/_table/_base/_enhanced_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ def mousePressEvent(self, e: QtGui.QMouseEvent) -> None:

def mouseMoveEvent(self, e: QtGui.QMouseEvent) -> None:
"""Scroll table plane when mouse is moved with right click."""
if e.buttons() == Qt.MouseButton.NoButton:
return None
if self._mouse_track.last_button == "right":
pos = e.pos()
dy = pos.y() - self._mouse_track.last_rightclick_pos.y()
Expand Down
Loading