Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to customize slider in qt? [closed]

Tags:

c++

qt

Is it possible to make a slider with an image? not as a background but like an image i pull up and down instead of the slider?

I have searched around and saw some examples of redrawing a slider, is it something like this i need to do, if so any examples you can link me too?

Also saw something called QML slider, can my project be achieved with that, if so any examples would be great!

I should mention im new to Qt and programming in general, so sorry in advance for any stupid mistakes i migth make .

like image 795
Sumsar1812 Avatar asked Feb 13 '23 23:02

Sumsar1812


2 Answers

With the Slider from Qt Quick Controls:

import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1

Item {
    width: 400
    height: 400
    Slider {
        anchors.centerIn: parent
        style: SliderStyle {
            handle: Image {
                source: "http://icons.iconarchive.com/icons/custom-icon-design/pretty-office-9/256/square-icon.png"
                width: 14
                height: 14
            }
        }
    }
}

custom-slider-handle

See SliderStyle's documentation for more information.

like image 98
Mitch Avatar answered Feb 15 '23 11:02

Mitch


In Qt, you can customize almost all of the UI with stylesheets. For the documentation and a quick tutorial, you might want to take a look to here and here.

I haven't tested this, but it might work(please note that you will have to adde the handle to the qrc):

setStyleSheet("QSlider::handle:horizontal{background-image:url(:/images/fancySliderHandle.png);}");

You might also want to check here for documentation(under QSlider). A syntax guide (in case you will be having trouble with my approach) can be found here.

like image 27
hellerve Avatar answered Feb 15 '23 11:02

hellerve