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

滑动条添加工具提示 #2

Closed
David-xian66 opened this issue Aug 11, 2022 · 1 comment
Closed

滑动条添加工具提示 #2

David-xian66 opened this issue Aug 11, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@David-xian66
Copy link

你好 最近看了这个项目 感觉非常不错 就是能否添加 在鼠标按下 hollow_handle_slider 中的
截屏2022-08-12 02 06 46
时 在上方显示百分比 (类似于 tool_tip

@zhiyiYo
Copy link
Owner

zhiyiYo commented Aug 12, 2022

@xianyongjian080402
我刚才更新了 ToolTip 的代码,现在它是顶层窗口了,拉取更新后,你可以使用下述代码实现一个带工具提示的滑动条:

# coding:utf-8
from PyQt5.QtCore import Qt, pyqtSignal, QPoint, QSize
from PyQt5.QtGui import QMouseEvent
from PyQt5.QtWidgets import QSlider

from tool_tip import ToolTip


class Slider(QSlider):
    """ A slider which can be clicked """

    clicked = pyqtSignal()

    def __init__(self, orient, parent=None):
        super().__init__(orient, parent=parent)
        self._toolTip = ToolTip('0', self)

    def mousePressEvent(self, e: QMouseEvent):
        super().mousePressEvent(e)
        if self.orientation() == Qt.Horizontal:
            value = int(e.pos().x() / self.width() * self.maximum())
        else:
            value = int((self.height()-e.pos().y()) /
                        self.height() * self.maximum())

        self.setValue(value)
        self.clicked.emit()

    def mouseMoveEvent(self, e):
        super().mouseMoveEvent(e)
        self._toolTip.setText(str(self.value()))
        if self.isSliderDown():
            pos = self.mapToGlobal(QPoint())
            pos.setX(pos.x() + e.x() - 13)
            self._toolTip.adjustPos(pos, QSize(26, 26))
            self._toolTip.show()

但是把滑动条把手移到最左端之后终端会报警:

UpdateLayeredWindowIndirect failed for ptDst=(857, 464), size=(68x61), dirty=(66x70 1, -2) (参数错误。)

暂时没想到解决办法,所以我没把这个滑动条一起提交了

@zhiyiYo zhiyiYo added the enhancement New feature or request label Aug 12, 2022
@zhiyiYo zhiyiYo changed the title 优化 滑动条添加工具提示 Aug 12, 2022
@zhiyiYo zhiyiYo closed this as completed Aug 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants