Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] How to reuse Slider as Component with different MouseAreas
Forum Update on Monday, May 27th 2025

[solved] How to reuse Slider as Component with different MouseAreas

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 589 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jago
    wrote on last edited by
    #1

    Hello!
    I have a Slider written in QML which consists of a slider field and a handle. There are some defined properties and a function:

    @property int value: 0 //the actual value of the slider
    property int maximum: 0 //the maximum value of slider scale
    property int minimum: 0 //the minimum value of the slider scale
    property int yMax: slider.height - handle.height //the maximum position the handle can be dragged to
    onValueChanged: updatePos(); //holds the value of the slider
    onYMaxChanged: updatePos(); //holds the value of the handle
    onMinimumChanged: updatePos();

    //calculates the position of the handle
    function updatePos()  {}@
    

    In the MouseArea of the handle I calculate the value:

    @onPositionChanged: {
    value = (maximum - minimum) * (handle.y) / yMax + minimum
    }@

    I want to use this Slider Component several times in another QML-File and I am doing it like this:

    @MySlider {
    id: slider1
    maximum: 450
    minimum: 220
    value: 220

              onPositionChanged: {
              slider1.value = mwBSC614_24_B.setHvVoltageLowLimit(value) // here I am setting some value for the backend
    

    }@

    So I want to set some values after the Position was changed, but it doesn't function. I think it is due to the fact that the signal positionChanged is not being recognized in this form. How can I solve this?

    Thank you beforehand,

    Best regards

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jago
      wrote on last edited by
      #2

      Solved: put a signal in the slider.qml and handled it in another.qml

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved