Giter Site home page Giter Site logo

Comments (1)

zhiyiYo avatar zhiyiYo commented on May 18, 2024

@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) (参数错误。)

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

from pyqt-fluent-widgets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.