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. Need to build a custom slider in qt 4
Forum Updated to NodeBB v4.3 + New Features

Need to build a custom slider in qt 4

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 5.1k Views 1 Watching
  • 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.
  • W Offline
    W Offline
    WhoopiCat
    wrote on last edited by
    #1

    All,

    I need to create a relatively complex slider widget. It needs to be able to take multiple sliders per line, which would be able to move independently of each other.

    I've created a notional version of it just putting the pixels on the screen with the .paintEvent() method of my custom widget, but of course the "blocks" on slider don't move.

    @ #include <QtGui>

    #include "gnzprimtl.h"
    #include <iostream>

    GNZPrimTL::GNZPrimTL(QWidget *parent)
    : QWidget(parent)
    {

     setWindowTitle(tr("Timeline Manager"));
    

    }

    void GNZPrimTL::paintEvent(QPaintEvent *)
    {

     QPainter painter(this);
     painter.setRenderHint(QPainter::Antialiasing);
    
     //top left is (0,0)
    
     //background and center stripe
     QColor black = QColor(0,0,0);
     QColor grey = QColor(127,127,127);
     QColor blue = QColor(0,0,255);
     QColor green = QColor(0,255,0);
     painter.setBrush(black);
     painter.drawRect(0, 0, width(), height());
     painter.setBrush(grey);
     painter.drawRoundedRect(width()*.025, (height()/2)*.85, width()*.95, height()*.2, 5.5, 5.5);
    
     // block 1
     painter.setBrush(green);
     painter.drawRoundedRect(width()*.1, height()*.05, width()*.1, height()*.9, 5.5, 5.5);
    
     // block 2
     painter.setBrush(blue);
     painter.drawRoundedRect(width()*.5, height()*.05, width()*.1, height()*.9, 5.5, 5.5);
    
     return;
    

    }@

    But of course the blocks don't move in response to mouse events. I'm supposing I need to derive the background-and-frame class from some kind of container widget, and then instantiate the blocks as a child of the container.

    Obviously not really sure where to start, though. Any help would be appreciated.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #2

      Your solution seems difficult. If I were you I would put several "QSliders":http://qt-project.org/doc/qt-5.0/qtwidgets/qslider.html inside a "QHBoxLayout":http://qt-project.org/doc/qt-5.0/qtwidgets/qhboxlayout.html (horizontal layout). Using "Qt style sheets":http://qt-project.org/doc/qt-4.8/stylesheet.html the appearance of the sliders can be customized.

      http://anavi.org/

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tilsitt
        wrote on last edited by
        #3

        Hi,

        Do you want something like "that":http://www.commontk.org/images/e/e1/CtkRangeSlider.png? You can check the source code of the "ctkRangeSlider":http://www.commontk.org/docs/html/classctkRangeSlider.html of "Commontk":http://www.commontk.org/index.php/Main_Page.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cincirin
          wrote on last edited by
          #4

          For a slider with two handles you can use "QxtSpanSlider":http://libqxt.bitbucket.org/doc/tip/qxtspanslider.html#details For a slider with multiple handles take a look to QxtSpanSlider implementation. btw ... What I've done in the past, subclass QSlider and create any number of QLabel with QSlider parent and implement mousePress & mouseMove events for these labels. It's not so hard to calculate label position in slider min/max ranges.

          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