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. Qt 4.8 QSlider handle size
Forum Updated to NodeBB v4.3 + New Features

Qt 4.8 QSlider handle size

Scheduled Pinned Locked Moved Solved General and Desktop
54 Posts 3 Posters 8.4k Views 2 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    I'm trying to set the handle size of a QSlider, I'm using Qt 4.8, I've tried:

    pobjSlider->setOrientation(Qt::Horizontal);
    const QString crstrStyleSheet(QString("QSlider::handle:horizontal {"
                                          "width: %1px;"
                                          "height: %2px; }").arg(cintHandleWidth)
                                                            .arg(cintHandleHeight));                                                                 
    pobjSlider->setStyleSheet(crstrStyleSheet);
    

    In the above example crstrStyleSheet contains:

    QSlider::handle::horizontal {width: 16px;height: 40px;}
    

    However I'm not seeing this and the slider handles just look like the defaults.

    Kind Regards,
    Sy

    jsulmJ 1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by
      #41

      Hi, as you say, the vertical slider looks ok but not the horizontal one. Sure you copied my program ok? If you check with wc it should say:

      70  166 2117 main.cpp
      

      and the md5 sum:

      md5sum main.cpp
      1eaf936e1072bf34bbb817a942295ada  main.cpp
      

      could you take a photo of the code after public slots: it should look like this:

      Screenshot 2022-04-08 at 08.11.38.png

      Sorry to bother but over the years, many times I've been struck by that "not copied verbatim" bug...

      SPlattenS 2 Replies Last reply
      0
      • SPlattenS SPlatten

        I'm trying to set the handle size of a QSlider, I'm using Qt 4.8, I've tried:

        pobjSlider->setOrientation(Qt::Horizontal);
        const QString crstrStyleSheet(QString("QSlider::handle:horizontal {"
                                              "width: %1px;"
                                              "height: %2px; }").arg(cintHandleWidth)
                                                                .arg(cintHandleHeight));                                                                 
        pobjSlider->setStyleSheet(crstrStyleSheet);
        

        In the above example crstrStyleSheet contains:

        QSlider::handle::horizontal {width: 16px;height: 40px;}
        

        However I'm not seeing this and the slider handles just look like the defaults.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @SPlatten said in Qt 4.8 QSlider handle size:

        %2ps

        Should it be %2px ?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by
          #3

          @jsulm , thank you, sorry that was just a typo when I was creating the post, the actual source code is px.

          Kind Regards,
          Sy

          SPlattenS 1 Reply Last reply
          0
          • SPlattenS SPlatten

            @jsulm , thank you, sorry that was just a typo when I was creating the post, the actual source code is px.

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #4

            Can anyone help on this?

            Kind Regards,
            Sy

            1 Reply Last reply
            0
            • hskoglundH Offline
              hskoglundH Offline
              hskoglund
              wrote on last edited by hskoglund
              #5

              Hi, I dug up some code of mine for customizing the slider so it looks like a slider on the sound-mixing board in a musical studio: first you create a vanilla QSlider then you call this function:

              void MainWindow::customizeSlider(QWidget* pSlider, QColor c, int nWidthInPixels, int nHeightInPixels)
              {
                  int nnBorderWidth  = 1;
                  int nnBorderRadius = 7;  // for nice rounded corners
                  QColor ccBorder("grey");
                  int nnLineWidth    = 2;
                  int nnMidLineWidth = 0;
              
                  QSlider* pTheRealSlider = dynamic_cast<QSlider*>(pSlider);
                  if (nullptr == pTheRealSlider)
                      return; // there was no QSlider* present, so skip this
              
              // construct and set the style sheet (2 parts, one for the groove and one for the handle)
                  pTheRealSlider->setStyleSheet(QString(
                      "QSlider::groove { background: transparent; height: %1px; } "
                      "QSlider::handle { background: %2; border-radius: %3px; border: %4px solid %5; width: %6px;}")
                      .arg(nHeightInPixels).arg(c.name()).arg(nnBorderRadius).arg(nnBorderWidth).arg(ccBorder.name()).arg(nWidthInPixels));
              
              // need to recreate the QSlider's groove? (the original is now invisible due to the stylesheet applied above)
                  QString sFrameObjectName = pTheRealSlider->objectName() + "Frame";  // we'll be using a QFrame
                  if (nullptr == pTheRealSlider->parentWidget()->findChild<QFrame*>(sFrameObjectName))
                  {
                  // new up a QFrame to act as a surrogate groove, use the same parent and geometry as the slider
                      QFrame* pFrame = new QFrame(pTheRealSlider->parentWidget());
                      pFrame->setGeometry(pTheRealSlider->geometry());
                      pFrame->setObjectName(sFrameObjectName);
                      pFrame->setFrameStyle((Qt::Horizontal == pTheRealSlider->orientation()) ? QFrame::HLine : QFrame::VLine);
                      pFrame->setFrameStyle(pFrame->frameStyle() | QFrame::Sunken);
                      pFrame->setLineWidth(nnLineWidth);
                      pFrame->setMidLineWidth(nnMidLineWidth);
              
                  // finally, change the z-order so that our custom groove is drawn under the handle (just like the real groove)
                      pFrame->stackUnder(pTheRealSlider);
                  }
              }
              

              This works in Qt5 so with a bit of luck it works in Qt4 also.
              Try different width and height arguments, it should change the handle size.

              Edit: you can toss that dynamic_cast<> , it was there so that I can iterate over all the widgets in my mainwindow and just change the sliders.

              SPlattenS 1 Reply Last reply
              3
              • hskoglundH hskoglund

                Hi, I dug up some code of mine for customizing the slider so it looks like a slider on the sound-mixing board in a musical studio: first you create a vanilla QSlider then you call this function:

                void MainWindow::customizeSlider(QWidget* pSlider, QColor c, int nWidthInPixels, int nHeightInPixels)
                {
                    int nnBorderWidth  = 1;
                    int nnBorderRadius = 7;  // for nice rounded corners
                    QColor ccBorder("grey");
                    int nnLineWidth    = 2;
                    int nnMidLineWidth = 0;
                
                    QSlider* pTheRealSlider = dynamic_cast<QSlider*>(pSlider);
                    if (nullptr == pTheRealSlider)
                        return; // there was no QSlider* present, so skip this
                
                // construct and set the style sheet (2 parts, one for the groove and one for the handle)
                    pTheRealSlider->setStyleSheet(QString(
                        "QSlider::groove { background: transparent; height: %1px; } "
                        "QSlider::handle { background: %2; border-radius: %3px; border: %4px solid %5; width: %6px;}")
                        .arg(nHeightInPixels).arg(c.name()).arg(nnBorderRadius).arg(nnBorderWidth).arg(ccBorder.name()).arg(nWidthInPixels));
                
                // need to recreate the QSlider's groove? (the original is now invisible due to the stylesheet applied above)
                    QString sFrameObjectName = pTheRealSlider->objectName() + "Frame";  // we'll be using a QFrame
                    if (nullptr == pTheRealSlider->parentWidget()->findChild<QFrame*>(sFrameObjectName))
                    {
                    // new up a QFrame to act as a surrogate groove, use the same parent and geometry as the slider
                        QFrame* pFrame = new QFrame(pTheRealSlider->parentWidget());
                        pFrame->setGeometry(pTheRealSlider->geometry());
                        pFrame->setObjectName(sFrameObjectName);
                        pFrame->setFrameStyle((Qt::Horizontal == pTheRealSlider->orientation()) ? QFrame::HLine : QFrame::VLine);
                        pFrame->setFrameStyle(pFrame->frameStyle() | QFrame::Sunken);
                        pFrame->setLineWidth(nnLineWidth);
                        pFrame->setMidLineWidth(nnMidLineWidth);
                
                    // finally, change the z-order so that our custom groove is drawn under the handle (just like the real groove)
                        pFrame->stackUnder(pTheRealSlider);
                    }
                }
                

                This works in Qt5 so with a bit of luck it works in Qt4 also.
                Try different width and height arguments, it should change the handle size.

                Edit: you can toss that dynamic_cast<> , it was there so that I can iterate over all the widgets in my mainwindow and just change the sliders.

                SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by
                #6

                @hskoglund , the background colour of the handle does change, but the width and height are not effected.

                Kind Regards,
                Sy

                1 Reply Last reply
                0
                • hskoglundH Offline
                  hskoglundH Offline
                  hskoglund
                  wrote on last edited by
                  #7

                  Hi, maybe it's because you on Qt4? It seems to work fine in Qt5:
                  J just tried a simple test project in Qt 5.15.2: create a new empty widget app and change your mainwindow.cpp to look like this:

                  #include "mainwindow.h"
                  #include "ui_mainwindow.h"
                  #include "qslider.h"
                  
                  MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
                  {
                      ui->setupUi(this);
                  
                      auto pSlider1 = new QSlider(Qt::Horizontal,this);
                      pSlider1->setGeometry(100,110,600,120);
                  
                      auto pSlider2 = new QSlider(Qt::Horizontal,this);
                      pSlider2->setGeometry(100,380,600,120);
                  
                  // customizing lambda
                      auto customizeSlider = [](QSlider* pSlider, QColor c,int nWidthInPixels, int nHeightInPixels)
                      {
                          int nnBorderWidth  = 1;
                          int nnBorderRadius = 7;  // for nice rounded corners
                          QColor ccBorder("grey");
                  
                          // construct and set the style sheet (2 parts, one for the groove and one for the handle)
                          pSlider->setStyleSheet(QString(
                              "QSlider::groove { background: transparent; height: %1px; } "
                              "QSlider::handle { background: %2; border-radius: %3px; border: %4px solid %5; width: %6px;}")
                              .arg(nHeightInPixels).arg(c.name()).arg(nnBorderRadius).arg(nnBorderWidth).arg(ccBorder.name()).arg(nWidthInPixels));
                      };
                  
                      connect(pSlider1,&QSlider::valueChanged,this,[customizeSlider,pSlider2] (int n) { customizeSlider(pSlider2,"red"  ,n + 50,n + 20); });
                      connect(pSlider2,&QSlider::valueChanged,this,[customizeSlider,pSlider1] (int n) { customizeSlider(pSlider1,"green",n + 50,n + 20); });
                  
                  }
                  
                  MainWindow::~MainWindow()
                  {
                      delete ui;
                  }
                  

                  when I run it (screndump):
                  Screenshot 2022-04-04 at 15.31.50.png

                  SPlattenS 1 Reply Last reply
                  3
                  • hskoglundH hskoglund

                    Hi, maybe it's because you on Qt4? It seems to work fine in Qt5:
                    J just tried a simple test project in Qt 5.15.2: create a new empty widget app and change your mainwindow.cpp to look like this:

                    #include "mainwindow.h"
                    #include "ui_mainwindow.h"
                    #include "qslider.h"
                    
                    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
                    {
                        ui->setupUi(this);
                    
                        auto pSlider1 = new QSlider(Qt::Horizontal,this);
                        pSlider1->setGeometry(100,110,600,120);
                    
                        auto pSlider2 = new QSlider(Qt::Horizontal,this);
                        pSlider2->setGeometry(100,380,600,120);
                    
                    // customizing lambda
                        auto customizeSlider = [](QSlider* pSlider, QColor c,int nWidthInPixels, int nHeightInPixels)
                        {
                            int nnBorderWidth  = 1;
                            int nnBorderRadius = 7;  // for nice rounded corners
                            QColor ccBorder("grey");
                    
                            // construct and set the style sheet (2 parts, one for the groove and one for the handle)
                            pSlider->setStyleSheet(QString(
                                "QSlider::groove { background: transparent; height: %1px; } "
                                "QSlider::handle { background: %2; border-radius: %3px; border: %4px solid %5; width: %6px;}")
                                .arg(nHeightInPixels).arg(c.name()).arg(nnBorderRadius).arg(nnBorderWidth).arg(ccBorder.name()).arg(nWidthInPixels));
                        };
                    
                        connect(pSlider1,&QSlider::valueChanged,this,[customizeSlider,pSlider2] (int n) { customizeSlider(pSlider2,"red"  ,n + 50,n + 20); });
                        connect(pSlider2,&QSlider::valueChanged,this,[customizeSlider,pSlider1] (int n) { customizeSlider(pSlider1,"green",n + 50,n + 20); });
                    
                    }
                    
                    MainWindow::~MainWindow()
                    {
                        delete ui;
                    }
                    

                    when I run it (screndump):
                    Screenshot 2022-04-04 at 15.31.50.png

                    SPlattenS Offline
                    SPlattenS Offline
                    SPlatten
                    wrote on last edited by
                    #8

                    @hskoglund , thats what I was afraid of.

                    Kind Regards,
                    Sy

                    1 Reply Last reply
                    0
                    • hskoglundH Offline
                      hskoglundH Offline
                      hskoglund
                      wrote on last edited by
                      #9

                      No reason to be afraid :-) Just tested on Qt 4.8.7:
                      create a main.pro containing this line:

                      SOURCES += main.cpp
                      

                      then create a main.cpp that looks like this:

                      #include <QApplication>
                      #include <qslider.h>
                      
                      class Window : public QWidget
                      {
                          Q_OBJECT
                      
                      public:
                          Window()
                          {
                              pSlider1 = new QSlider(Qt::Horizontal,this);
                              pSlider1->setGeometry(10,110,500,130);
                      
                              pSlider2 = new QSlider(Qt::Horizontal,this);
                              pSlider2->setGeometry(10,330,500,130);
                      
                              connect(pSlider1,SIGNAL(valueChanged(int)),this,SLOT(valueChanged1(int)));
                              connect(pSlider2,SIGNAL(valueChanged(int)),this,SLOT(valueChanged2(int)));
                          }
                      
                          void customizeSlider(QSlider* pSlider, QColor c,int nWidthInPixels, int nHeightInPixels)
                          {
                              int nnBorderWidth  = 1;
                              int nnBorderRadius = 7;  // for nice rounded corners
                              QColor ccBorder("grey");
                      
                              pSlider->setStyleSheet(QString(
                              "QSlider::groove { background: transparent; height: %1px; } "
                              "QSlider::handle { background: %2; border-radius: %3px; border: %4px solid %5; width: %6px;}")
                              .arg(nHeightInPixels).arg(c.name()).arg(nnBorderRadius).arg(nnBorderWidth).arg(ccBorder.name()).arg(nWidthInPixels));
                          };
                      
                          QSlider* pSlider1;
                          QSlider* pSlider2;
                      
                      public slots:
                          void valueChanged1(int value) { customizeSlider(pSlider2,QColor("green"), 60 + value, 30 + value); }
                          void valueChanged2(int value) { customizeSlider(pSlider1,QColor("red"  ), 60 + value, 30 + value); }
                      };
                      
                      int main(int argc, char *argv[])
                      {
                          QApplication app(argc, argv);
                          Window window;
                          window.show();
                          return app.exec();
                      }
                      
                      #include "main.moc"
                      

                      then invoke the qtvars.bat, qmake and make and you get this: (very similar to Qt5):
                      Screenshot 2022-04-04 at 18.37.25.png

                      SPlattenS 1 Reply Last reply
                      2
                      • hskoglundH hskoglund

                        No reason to be afraid :-) Just tested on Qt 4.8.7:
                        create a main.pro containing this line:

                        SOURCES += main.cpp
                        

                        then create a main.cpp that looks like this:

                        #include <QApplication>
                        #include <qslider.h>
                        
                        class Window : public QWidget
                        {
                            Q_OBJECT
                        
                        public:
                            Window()
                            {
                                pSlider1 = new QSlider(Qt::Horizontal,this);
                                pSlider1->setGeometry(10,110,500,130);
                        
                                pSlider2 = new QSlider(Qt::Horizontal,this);
                                pSlider2->setGeometry(10,330,500,130);
                        
                                connect(pSlider1,SIGNAL(valueChanged(int)),this,SLOT(valueChanged1(int)));
                                connect(pSlider2,SIGNAL(valueChanged(int)),this,SLOT(valueChanged2(int)));
                            }
                        
                            void customizeSlider(QSlider* pSlider, QColor c,int nWidthInPixels, int nHeightInPixels)
                            {
                                int nnBorderWidth  = 1;
                                int nnBorderRadius = 7;  // for nice rounded corners
                                QColor ccBorder("grey");
                        
                                pSlider->setStyleSheet(QString(
                                "QSlider::groove { background: transparent; height: %1px; } "
                                "QSlider::handle { background: %2; border-radius: %3px; border: %4px solid %5; width: %6px;}")
                                .arg(nHeightInPixels).arg(c.name()).arg(nnBorderRadius).arg(nnBorderWidth).arg(ccBorder.name()).arg(nWidthInPixels));
                            };
                        
                            QSlider* pSlider1;
                            QSlider* pSlider2;
                        
                        public slots:
                            void valueChanged1(int value) { customizeSlider(pSlider2,QColor("green"), 60 + value, 30 + value); }
                            void valueChanged2(int value) { customizeSlider(pSlider1,QColor("red"  ), 60 + value, 30 + value); }
                        };
                        
                        int main(int argc, char *argv[])
                        {
                            QApplication app(argc, argv);
                            Window window;
                            window.show();
                            return app.exec();
                        }
                        
                        #include "main.moc"
                        

                        then invoke the qtvars.bat, qmake and make and you get this: (very similar to Qt5):
                        Screenshot 2022-04-04 at 18.37.25.png

                        SPlattenS Offline
                        SPlattenS Offline
                        SPlatten
                        wrote on last edited by SPlatten
                        #10

                        @hskoglund , in your example the orientation of both sliders is horizontal, try setting one of those to vertical, I don't understand what I've done wrong, what I'm seeing in the Application Output, for a vertical slider:

                        QSlider::handle {width:10px;height:40px;}
                        

                        For horizontal slider:

                        QSlider::handle {width:40px;height:10px;}
                        

                        However when rendered they look like they are exactly the wrong way around and I just can't see why. In my set-up configuration file I've swapped around the width and height for each so I see for vertical:

                        QSlider::handle {width:40px;height:10px;}
                        

                        For horizontal slider:

                        QSlider::handle {width:10px;height:40px;}
                        

                        However when rendered there is no difference form the previous where the width and heights are swapped.

                        I've just tried setting very large figures for width and height and they aren't working, the backgound colour style does work but the width and height have no effect.

                        I don't have groove in the style, is that relevant?

                        Kind Regards,
                        Sy

                        1 Reply Last reply
                        0
                        • hskoglundH Offline
                          hskoglundH Offline
                          hskoglund
                          wrote on last edited by
                          #11

                          Hi, oh but you have to groove in the stylesheet otherwise you'll get the nothing happens effect. This is probably why it doesn't work for you :-(

                          SPlattenS 1 Reply Last reply
                          0
                          • hskoglundH hskoglund

                            Hi, oh but you have to groove in the stylesheet otherwise you'll get the nothing happens effect. This is probably why it doesn't work for you :-(

                            SPlattenS Offline
                            SPlattenS Offline
                            SPlatten
                            wrote on last edited by
                            #12

                            @hskoglund , I wish I could say that solved the problem, it has not.

                            Kind Regards,
                            Sy

                            1 Reply Last reply
                            0
                            • hskoglundH Offline
                              hskoglundH Offline
                              hskoglund
                              wrote on last edited by
                              #13

                              Hmm, vertical sliders work the same for me on Qt 4.8.7, I changed main.cpp to:

                              #include <QApplication>
                              #include <qslider.h>
                              
                              class Window : public QWidget
                              {
                                  Q_OBJECT
                              
                              public:
                                  Window()
                                  {
                                      pSlider1 = new QSlider(Qt::Vertical,this);
                                      pSlider1->setGeometry(110,10,130,500);
                              
                                      pSlider2 = new QSlider(Qt::Vertical,this);
                                      pSlider2->setGeometry(330,10,130,500);
                              
                                      connect(pSlider1,SIGNAL(valueChanged(int)),this,SLOT(valueChanged1(int)));
                                      connect(pSlider2,SIGNAL(valueChanged(int)),this,SLOT(valueChanged2(int)));
                                  }
                              
                                  void customizeSlider(QSlider* pSlider, QColor c,int nWidthInPixels, int nHeightInPixels)
                                  {
                                      int nnBorderWidth  = 1;
                                      int nnBorderRadius = 7;  // for nice rounded corners
                                      QColor ccBorder("grey");
                              
                                      pSlider->setStyleSheet(QString(
                                      "QSlider::groove { background: transparent; width: %1px; } "
                                      "QSlider::handle { background: %2; border-radius: %3px; border: %4px solid %5; height: %6px;}")
                                      .arg(nHeightInPixels).arg(c.name()).arg(nnBorderRadius).arg(nnBorderWidth).arg(ccBorder.name()).arg(nWidthInPixels));
                                  };
                              
                                  QSlider* pSlider1;
                                  QSlider* pSlider2;
                              
                              public slots:
                                  void valueChanged1(int value) { customizeSlider(pSlider2,QColor("green"), 30 + value, 80 + value); }
                                  void valueChanged2(int value) { customizeSlider(pSlider1,QColor("red"  ), 30 + value, 80 + value); }
                              };
                              
                              int main(int argc, char *argv[])
                              {
                                  QApplication app(argc, argv);
                                  Window window;
                                  window.show();
                                  return app.exec();
                              }
                              
                              #include "main.moc"
                              

                              and I get this:
                              Screenshot 2022-04-05 at 17.02.11.png

                              Are you on Qt 4.8..7 also?

                              SPlattenS 1 Reply Last reply
                              1
                              • hskoglundH hskoglund

                                Hmm, vertical sliders work the same for me on Qt 4.8.7, I changed main.cpp to:

                                #include <QApplication>
                                #include <qslider.h>
                                
                                class Window : public QWidget
                                {
                                    Q_OBJECT
                                
                                public:
                                    Window()
                                    {
                                        pSlider1 = new QSlider(Qt::Vertical,this);
                                        pSlider1->setGeometry(110,10,130,500);
                                
                                        pSlider2 = new QSlider(Qt::Vertical,this);
                                        pSlider2->setGeometry(330,10,130,500);
                                
                                        connect(pSlider1,SIGNAL(valueChanged(int)),this,SLOT(valueChanged1(int)));
                                        connect(pSlider2,SIGNAL(valueChanged(int)),this,SLOT(valueChanged2(int)));
                                    }
                                
                                    void customizeSlider(QSlider* pSlider, QColor c,int nWidthInPixels, int nHeightInPixels)
                                    {
                                        int nnBorderWidth  = 1;
                                        int nnBorderRadius = 7;  // for nice rounded corners
                                        QColor ccBorder("grey");
                                
                                        pSlider->setStyleSheet(QString(
                                        "QSlider::groove { background: transparent; width: %1px; } "
                                        "QSlider::handle { background: %2; border-radius: %3px; border: %4px solid %5; height: %6px;}")
                                        .arg(nHeightInPixels).arg(c.name()).arg(nnBorderRadius).arg(nnBorderWidth).arg(ccBorder.name()).arg(nWidthInPixels));
                                    };
                                
                                    QSlider* pSlider1;
                                    QSlider* pSlider2;
                                
                                public slots:
                                    void valueChanged1(int value) { customizeSlider(pSlider2,QColor("green"), 30 + value, 80 + value); }
                                    void valueChanged2(int value) { customizeSlider(pSlider1,QColor("red"  ), 30 + value, 80 + value); }
                                };
                                
                                int main(int argc, char *argv[])
                                {
                                    QApplication app(argc, argv);
                                    Window window;
                                    window.show();
                                    return app.exec();
                                }
                                
                                #include "main.moc"
                                

                                and I get this:
                                Screenshot 2022-04-05 at 17.02.11.png

                                Are you on Qt 4.8..7 also?

                                SPlattenS Offline
                                SPlattenS Offline
                                SPlatten
                                wrote on last edited by
                                #14

                                @hskoglund , can you make your examples a bit more obvious? Make the handle horizontal wide and thin, the vertical handle thin and tall ?

                                I want my sliders to look like sliders with the default groove and ticks.

                                Kind Regards,
                                Sy

                                1 Reply Last reply
                                0
                                • hskoglundH Offline
                                  hskoglundH Offline
                                  hskoglund
                                  wrote on last edited by hskoglund
                                  #15

                                  Hi, I simplified, Edit: removed the colors so that the sliders look more standard sliders :-)

                                  #include <QApplication>
                                  #include <qslider.h>
                                  
                                  class Window : public QWidget
                                  {
                                      Q_OBJECT
                                  
                                  // setup 2 real sliders and 2 "followers" that are stacked under the real ones
                                      QSlider* pSlider1;
                                      QSlider* pSlider1Follower;
                                      QSlider* pSlider2;
                                      QSlider* pSlider2Follower;
                                  
                                  public:
                                      Window()
                                      {
                                          pSlider1 = new QSlider(Qt::Horizontal,this);
                                          pSlider1->setGeometry(30,300,600,40);
                                  
                                          pSlider1Follower = new QSlider(Qt::Horizontal,this);
                                          pSlider1Follower->setGeometry(30,300,600,40);
                                          pSlider1Follower->setTickPosition(QSlider::TicksBothSides);
                                          pSlider1Follower->setTickInterval(2);
                                          pSlider1Follower->setSingleStep(1);
                                          pSlider1Follower->stackUnder(pSlider1);
                                  
                                          pSlider2 = new QSlider(Qt::Vertical,this);
                                          pSlider2->setGeometry(660,30,40,600);
                                  
                                          pSlider2Follower = new QSlider(Qt::Vertical,this);
                                          pSlider2Follower->setGeometry(660,30,40,600);
                                          pSlider2Follower->setTickPosition(QSlider::TicksBothSides);
                                          pSlider2Follower->setTickInterval(2);
                                          pSlider2Follower->setSingleStep(1);
                                          pSlider2Follower->stackUnder(pSlider2);
                                  
                                          connect(pSlider1,SIGNAL(valueChanged(int)),this,SLOT(valueChanged1(int)));
                                          connect(pSlider2,SIGNAL(valueChanged(int)),this,SLOT(valueChanged2(int)));
                                  
                                      // do an initial update/refresh
                                          valueChanged1(0);
                                          valueChanged2(0);
                                      }
                                  
                                  public slots:
                                      void valueChanged1(int value)
                                      {
                                          pSlider1Follower->setValue(value);
                                  
                                          pSlider2->setStyleSheet(QString("QSlider::groove { background: transparent; width: 40px; } "
                                         "QSlider::handle { background: #eeeeee; border:1px solid grey; height: %1px;}").arg(2 * value + 10));
                                      }
                                  
                                      void valueChanged2(int value)
                                      {
                                          pSlider2Follower->setValue(value);
                                  
                                          pSlider1->setStyleSheet(QString("QSlider::groove { background: transparent; height: 40px; } "
                                         "QSlider::handle { background: #eeeeee; border:1px solid grey; width: %1px;}").arg(2 * value + 10));
                                      }
                                  };
                                  
                                  int main(int argc, char *argv[])
                                  {
                                      QApplication app(argc, argv);
                                      Window window;
                                      window.show();
                                      return app.exec();
                                  }
                                  
                                  #include "main.moc"
                                  

                                  and now it looks like this:
                                  Screenshot 2022-04-06 at 00.04.35.png

                                  SPlattenS 1 Reply Last reply
                                  2
                                  • hskoglundH hskoglund

                                    Hi, I simplified, Edit: removed the colors so that the sliders look more standard sliders :-)

                                    #include <QApplication>
                                    #include <qslider.h>
                                    
                                    class Window : public QWidget
                                    {
                                        Q_OBJECT
                                    
                                    // setup 2 real sliders and 2 "followers" that are stacked under the real ones
                                        QSlider* pSlider1;
                                        QSlider* pSlider1Follower;
                                        QSlider* pSlider2;
                                        QSlider* pSlider2Follower;
                                    
                                    public:
                                        Window()
                                        {
                                            pSlider1 = new QSlider(Qt::Horizontal,this);
                                            pSlider1->setGeometry(30,300,600,40);
                                    
                                            pSlider1Follower = new QSlider(Qt::Horizontal,this);
                                            pSlider1Follower->setGeometry(30,300,600,40);
                                            pSlider1Follower->setTickPosition(QSlider::TicksBothSides);
                                            pSlider1Follower->setTickInterval(2);
                                            pSlider1Follower->setSingleStep(1);
                                            pSlider1Follower->stackUnder(pSlider1);
                                    
                                            pSlider2 = new QSlider(Qt::Vertical,this);
                                            pSlider2->setGeometry(660,30,40,600);
                                    
                                            pSlider2Follower = new QSlider(Qt::Vertical,this);
                                            pSlider2Follower->setGeometry(660,30,40,600);
                                            pSlider2Follower->setTickPosition(QSlider::TicksBothSides);
                                            pSlider2Follower->setTickInterval(2);
                                            pSlider2Follower->setSingleStep(1);
                                            pSlider2Follower->stackUnder(pSlider2);
                                    
                                            connect(pSlider1,SIGNAL(valueChanged(int)),this,SLOT(valueChanged1(int)));
                                            connect(pSlider2,SIGNAL(valueChanged(int)),this,SLOT(valueChanged2(int)));
                                    
                                        // do an initial update/refresh
                                            valueChanged1(0);
                                            valueChanged2(0);
                                        }
                                    
                                    public slots:
                                        void valueChanged1(int value)
                                        {
                                            pSlider1Follower->setValue(value);
                                    
                                            pSlider2->setStyleSheet(QString("QSlider::groove { background: transparent; width: 40px; } "
                                           "QSlider::handle { background: #eeeeee; border:1px solid grey; height: %1px;}").arg(2 * value + 10));
                                        }
                                    
                                        void valueChanged2(int value)
                                        {
                                            pSlider2Follower->setValue(value);
                                    
                                            pSlider1->setStyleSheet(QString("QSlider::groove { background: transparent; height: 40px; } "
                                           "QSlider::handle { background: #eeeeee; border:1px solid grey; width: %1px;}").arg(2 * value + 10));
                                        }
                                    };
                                    
                                    int main(int argc, char *argv[])
                                    {
                                        QApplication app(argc, argv);
                                        Window window;
                                        window.show();
                                        return app.exec();
                                    }
                                    
                                    #include "main.moc"
                                    

                                    and now it looks like this:
                                    Screenshot 2022-04-06 at 00.04.35.png

                                    SPlattenS Offline
                                    SPlattenS Offline
                                    SPlatten
                                    wrote on last edited by
                                    #16

                                    @hskoglund , ok, now that looks like what I'm seeing however what I am trying to achieve is a taller handle on the horizontal slider and a wider handler on the vertical, which will not happen.

                                    Kind Regards,
                                    Sy

                                    1 Reply Last reply
                                    0
                                    • hskoglundH Offline
                                      hskoglundH Offline
                                      hskoglund
                                      wrote on last edited by
                                      #17

                                      Hi, try:

                                      #include <QApplication>
                                      #include <qslider.h>
                                      
                                      class Window : public QWidget
                                      {
                                          Q_OBJECT
                                      
                                      // setup 2 real sliders and 2 "followers" that are stacked under the real ones
                                          QSlider* pSlider1;
                                          QSlider* pSlider1Follower;
                                          QSlider* pSlider2;
                                          QSlider* pSlider2Follower;
                                      
                                      public:
                                          Window()
                                          {
                                              setGeometry(130,130,860,660);
                                      
                                              pSlider1 = new QSlider(Qt::Horizontal,this);
                                              pSlider1->setGeometry(30,300,600,230);
                                      
                                              pSlider1Follower = new QSlider(Qt::Horizontal,this);
                                              pSlider1Follower->setGeometry(30,300,600,230);
                                              pSlider1Follower->setTickPosition(QSlider::TicksBothSides);
                                              pSlider1Follower->setTickInterval(2);
                                              pSlider1Follower->setSingleStep(1);
                                              pSlider1Follower->stackUnder(pSlider1);
                                      
                                              pSlider2 = new QSlider(Qt::Vertical,this);
                                              pSlider2->setGeometry(660,30,230,600);
                                      
                                              pSlider2Follower = new QSlider(Qt::Vertical,this);
                                              pSlider2Follower->setGeometry(660,30,230,600);
                                              pSlider2Follower->setTickPosition(QSlider::TicksBothSides);
                                              pSlider2Follower->setTickInterval(2);
                                              pSlider2Follower->setSingleStep(1);
                                              pSlider2Follower->stackUnder(pSlider2);
                                      
                                              connect(pSlider1,SIGNAL(valueChanged(int)),this,SLOT(valueChanged1(int)));
                                              connect(pSlider2,SIGNAL(valueChanged(int)),this,SLOT(valueChanged2(int)));
                                      
                                          // do an initial update/refresh
                                              valueChanged1(0);
                                              valueChanged2(0);
                                          }
                                      
                                      public slots:
                                          void valueChanged1(int value)
                                          {
                                              pSlider1Follower->setValue(value);
                                      
                                              pSlider2->setStyleSheet(QString("QSlider::groove { background: transparent; width: %1px; } "
                                             "QSlider::handle { background: #eeeeee; border:1px solid grey; height: %2px;}").arg(value + 30).arg(value * 2 + 10));
                                      
                                              pSlider2->setGeometry(660,30,2 * value + 30,600);
                                              pSlider2Follower->setGeometry(660,30,2 * value + 30,600);
                                          }
                                      
                                          void valueChanged2(int value)
                                          {
                                              pSlider2Follower->setValue(value);
                                      
                                              pSlider1->setStyleSheet(QString("QSlider::groove { background: transparent; height: %1px; } "
                                             "QSlider::handle { background: #eeeeee; border:1px solid grey; width: %2px;}").arg(value + 30).arg(value * 2 + 10));
                                      
                                              pSlider1->setGeometry(30,300,600,2 * value + 30);
                                              pSlider1Follower->setGeometry(30,300,600,2 * value + 30);
                                          }
                                      };
                                      
                                      int main(int argc, char *argv[])
                                      {
                                          QApplication app(argc, argv);
                                          Window window;
                                          window.show();
                                          return app.exec();
                                      }
                                      
                                      #include "main.moc"
                                      

                                      to get this:
                                      Screenshot 2022-04-06 at 08.17.58.png

                                      SPlattenS 1 Reply Last reply
                                      1
                                      • hskoglundH hskoglund

                                        Hi, try:

                                        #include <QApplication>
                                        #include <qslider.h>
                                        
                                        class Window : public QWidget
                                        {
                                            Q_OBJECT
                                        
                                        // setup 2 real sliders and 2 "followers" that are stacked under the real ones
                                            QSlider* pSlider1;
                                            QSlider* pSlider1Follower;
                                            QSlider* pSlider2;
                                            QSlider* pSlider2Follower;
                                        
                                        public:
                                            Window()
                                            {
                                                setGeometry(130,130,860,660);
                                        
                                                pSlider1 = new QSlider(Qt::Horizontal,this);
                                                pSlider1->setGeometry(30,300,600,230);
                                        
                                                pSlider1Follower = new QSlider(Qt::Horizontal,this);
                                                pSlider1Follower->setGeometry(30,300,600,230);
                                                pSlider1Follower->setTickPosition(QSlider::TicksBothSides);
                                                pSlider1Follower->setTickInterval(2);
                                                pSlider1Follower->setSingleStep(1);
                                                pSlider1Follower->stackUnder(pSlider1);
                                        
                                                pSlider2 = new QSlider(Qt::Vertical,this);
                                                pSlider2->setGeometry(660,30,230,600);
                                        
                                                pSlider2Follower = new QSlider(Qt::Vertical,this);
                                                pSlider2Follower->setGeometry(660,30,230,600);
                                                pSlider2Follower->setTickPosition(QSlider::TicksBothSides);
                                                pSlider2Follower->setTickInterval(2);
                                                pSlider2Follower->setSingleStep(1);
                                                pSlider2Follower->stackUnder(pSlider2);
                                        
                                                connect(pSlider1,SIGNAL(valueChanged(int)),this,SLOT(valueChanged1(int)));
                                                connect(pSlider2,SIGNAL(valueChanged(int)),this,SLOT(valueChanged2(int)));
                                        
                                            // do an initial update/refresh
                                                valueChanged1(0);
                                                valueChanged2(0);
                                            }
                                        
                                        public slots:
                                            void valueChanged1(int value)
                                            {
                                                pSlider1Follower->setValue(value);
                                        
                                                pSlider2->setStyleSheet(QString("QSlider::groove { background: transparent; width: %1px; } "
                                               "QSlider::handle { background: #eeeeee; border:1px solid grey; height: %2px;}").arg(value + 30).arg(value * 2 + 10));
                                        
                                                pSlider2->setGeometry(660,30,2 * value + 30,600);
                                                pSlider2Follower->setGeometry(660,30,2 * value + 30,600);
                                            }
                                        
                                            void valueChanged2(int value)
                                            {
                                                pSlider2Follower->setValue(value);
                                        
                                                pSlider1->setStyleSheet(QString("QSlider::groove { background: transparent; height: %1px; } "
                                               "QSlider::handle { background: #eeeeee; border:1px solid grey; width: %2px;}").arg(value + 30).arg(value * 2 + 10));
                                        
                                                pSlider1->setGeometry(30,300,600,2 * value + 30);
                                                pSlider1Follower->setGeometry(30,300,600,2 * value + 30);
                                            }
                                        };
                                        
                                        int main(int argc, char *argv[])
                                        {
                                            QApplication app(argc, argv);
                                            Window window;
                                            window.show();
                                            return app.exec();
                                        }
                                        
                                        #include "main.moc"
                                        

                                        to get this:
                                        Screenshot 2022-04-06 at 08.17.58.png

                                        SPlattenS Offline
                                        SPlattenS Offline
                                        SPlatten
                                        wrote on last edited by SPlatten
                                        #18

                                        @hskoglund , your handles look like they both need rotating 90 degrees.

                                        The CSS I'm using:

                                        For Vertical:

                                        QSlider::handle:vertical {width:80px;height10px;}
                                        

                                        For Horizontal:

                                        QSlider::handle:horizontal {width:10px;height:80px;}
                                        

                                        If I add:

                                        QSlider::groove:vertical {background: transparent;}
                                        

                                        I get nothing displayed at all.

                                        Kind Regards,
                                        Sy

                                        1 Reply Last reply
                                        0
                                        • hskoglundH Offline
                                          hskoglundH Offline
                                          hskoglund
                                          wrote on last edited by
                                          #19

                                          When you run my example, does it work?

                                          SPlattenS 1 Reply Last reply
                                          0
                                          • hskoglundH hskoglund

                                            When you run my example, does it work?

                                            SPlattenS Offline
                                            SPlattenS Offline
                                            SPlatten
                                            wrote on last edited by SPlatten
                                            #20

                                            @hskoglund , I'm not sure what you are trying to achieve in your code, I just typed it in and run and it looks very wrong. What is the purpose of the sliders on top of sliders?

                                            I can't be distracted by this, it isn't right and the results are still not right.

                                            When I launch the application I see four sliders, two on tope of the first two, with handles in different orientations, the vertical slider has a square handle that is wider than the handle it overlaps, the handle underneath has a texture (grip) to it but it appears to be rounded and vertical.

                                            Kind Regards,
                                            Sy

                                            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