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. Signal/Slots doesn't work with QSlider and QDoubleSpinBox
Forum Updated to NodeBB v4.3 + New Features

Signal/Slots doesn't work with QSlider and QDoubleSpinBox

Scheduled Pinned Locked Moved Solved General and Desktop
signals&slotsqsliderqdoublespinbox
24 Posts 5 Posters 13.0k Views 3 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.
  • jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #21

    I did not test this code:

    void MyClass::sliderHeightChanged(int value)
    {
        double diff = m_heightSpinBox->value - value;
        m_heightSpinBox->setValue(value);
        m_widthSpinBox->setValue(m_widthSpinBox->value + diff);
    }
    
    void MyClass::sliderWidthChanged(int value)
    {
    
        double diff = m_widthSpinBox->value - value;
        m_widthSpinBox->setValue(value);
        m_HeightSpinBox->setValue(m_heightSpinBox->value + diff);
    }
    
    if (m_keepRatioCheckBox->isChecked())
    {
        connect(sliderHeight, &QSlider::valueChanged, this, &MyClass::sliderHeightChanged);
        connect(sliderWidth, &QSlider::valueChanged, this, &MyClass::sliderWidthChanged);
    }
    

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

    ? 3 Replies Last reply
    0
    • jsulmJ jsulm

      I did not test this code:

      void MyClass::sliderHeightChanged(int value)
      {
          double diff = m_heightSpinBox->value - value;
          m_heightSpinBox->setValue(value);
          m_widthSpinBox->setValue(m_widthSpinBox->value + diff);
      }
      
      void MyClass::sliderWidthChanged(int value)
      {
      
          double diff = m_widthSpinBox->value - value;
          m_widthSpinBox->setValue(value);
          m_HeightSpinBox->setValue(m_heightSpinBox->value + diff);
      }
      
      if (m_keepRatioCheckBox->isChecked())
      {
          connect(sliderHeight, &QSlider::valueChanged, this, &MyClass::sliderHeightChanged);
          connect(sliderWidth, &QSlider::valueChanged, this, &MyClass::sliderWidthChanged);
      }
      
      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #22

      @jsulm
      I have written all the Code for the Dialog in a Header file..

      1 Reply Last reply
      0
      • jsulmJ jsulm

        I did not test this code:

        void MyClass::sliderHeightChanged(int value)
        {
            double diff = m_heightSpinBox->value - value;
            m_heightSpinBox->setValue(value);
            m_widthSpinBox->setValue(m_widthSpinBox->value + diff);
        }
        
        void MyClass::sliderWidthChanged(int value)
        {
        
            double diff = m_widthSpinBox->value - value;
            m_widthSpinBox->setValue(value);
            m_HeightSpinBox->setValue(m_heightSpinBox->value + diff);
        }
        
        if (m_keepRatioCheckBox->isChecked())
        {
            connect(sliderHeight, &QSlider::valueChanged, this, &MyClass::sliderHeightChanged);
            connect(sliderWidth, &QSlider::valueChanged, this, &MyClass::sliderWidthChanged);
        }
        
        ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #23

        @jsulm
        Where can i insert your Code?

        class ResizeImageDialog : public QDialog
        {
        Q_OBJECT
        
        double         m_ratio;
        
        QLabel         *m_widthLabel;
        QLabel         *m_hightLabel;
        QDoubleSpinBox *m_widthSpinBox;
        QDoubleSpinBox *m_hightSpinBox;
        QRadioButton   *m_keepRatioCheckBox;
        QPushButton    *m_okButton;
        QPushButton    *m_cancelButton;
        QSlider        *sliderWidth;
        QSlider        *sliderHeight;
        QHBoxLayout    *m_widthLayout;
        QHBoxLayout    *m_hightLayout;
        QHBoxLayout    *m_buttonLayout;
        QVBoxLayout    *m_generalLayout;
        
        
        public:
        ResizeImageDialog(QWidget * parent = 0, double imageWidth = 100.0, double imageHight = 100.0) : QDialog(parent)
        {
           m_widthLabel = new QLabel("Breite");
           m_hightLabel = new QLabel("Höhe");
        
           m_widthSpinBox = new QDoubleSpinBox;
           m_widthSpinBox->setMaximum(1500);
           m_widthSpinBox->setValue(imageWidth);
        
        
           sliderHeight = new QSlider(Qt::Horizontal);
           sliderHeight->setMaximum(1500);
           sliderHeight->setMinimum(0);
        
        
        
        
           sliderWidth = new QSlider(Qt::Horizontal);
           sliderWidth->setMaximum(1500);
           sliderWidth->setMinimum(0);
        
        
           m_hightSpinBox = new QDoubleSpinBox;
           m_hightSpinBox->setMaximum(1500);
           m_hightSpinBox->setValue(imageHight);
        
           connect(sliderHeight, &QSlider::valueChanged, m_hightSpinBox, &QDoubleSpinBox::setValue);
           connect(sliderWidth, &QSlider::valueChanged, m_widthSpinBox, &QDoubleSpinBox::setValue);
        
           m_ratio = imageWidth / imageHight;
        
           m_keepRatioCheckBox = new QRadioButton("Keep ratio", this);
           m_keepRatioCheckBox->setChecked(false);
        
        
           if (m_keepRatioCheckBox->isChecked())
           {
              connect(sliderHeight, &QSlider::valueChanged, m_hightSpinBox, &QDoubleSpinBox::setValue);
              connect(sliderHeight, &QSlider::valueChanged, m_widthSpinBox, &QDoubleSpinBox::setValue);
              connect(sliderWidth, &QSlider::valueChanged, m_hightSpinBox, &QDoubleSpinBox::setValue);
              connect(sliderWidth, &QSlider::valueChanged, m_widthSpinBox, &QDoubleSpinBox::setValue);
              m_hightSpinBox->setValue(25.8);
           }
        
           
           
           
           
        
           m_widthLayout = new QHBoxLayout;
           m_widthLayout->addWidget(m_widthLabel);
           m_widthLayout->addWidget(m_widthSpinBox);
           m_widthLayout->addWidget(sliderWidth);
        
           m_hightLayout = new QHBoxLayout;
           m_hightLayout->addWidget(m_hightLabel);
           m_hightLayout->addWidget(m_hightSpinBox);
           m_hightLayout->addWidget(sliderHeight);
        
           m_okButton = new QPushButton("Ok");
           connect(m_okButton, SIGNAL(clicked()), this, SLOT(accept()));
        
           m_cancelButton = new QPushButton("Abbrechen");
           connect(m_cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
        
           m_buttonLayout = new QHBoxLayout;
           m_buttonLayout->addStretch();
           m_buttonLayout->addWidget(m_okButton);
           m_buttonLayout->addWidget(m_cancelButton);
        
           m_generalLayout = new QVBoxLayout;
           m_generalLayout->addLayout(m_widthLayout);
           m_generalLayout->addLayout(m_hightLayout);
           m_generalLayout->addWidget(m_keepRatioCheckBox);
           m_generalLayout->addLayout(m_buttonLayout);
           setLayout(m_generalLayout);
        
           setMaximumSize(500, 300);
           resize(350, 100);
           setModal(true);
           //resize(670,630);
           setWindowTitle(tr("Bildgröße ändern"));
           setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
        }
        
        static QPair<double, double> getNewSize(QWidget * parent = 0, double imageWidth = 100.0, double imageHight = 100.0)
        {
           ResizeImageDialog dlg(parent, imageWidth, imageHight);
        
           dlg.exec();
        
        
        
           QPair<double, double> size;
           size.first  = dlg.m_widthSpinBox->value();
           size.second = dlg.m_hightSpinBox->value();
           return size;
        }
        };
        
        
        #endif // PAGESTEXTEDIT_H
        
        
        

        A .cpp file is not there for the dialog

        1 Reply Last reply
        0
        • jsulmJ jsulm

          I did not test this code:

          void MyClass::sliderHeightChanged(int value)
          {
              double diff = m_heightSpinBox->value - value;
              m_heightSpinBox->setValue(value);
              m_widthSpinBox->setValue(m_widthSpinBox->value + diff);
          }
          
          void MyClass::sliderWidthChanged(int value)
          {
          
              double diff = m_widthSpinBox->value - value;
              m_widthSpinBox->setValue(value);
              m_HeightSpinBox->setValue(m_heightSpinBox->value + diff);
          }
          
          if (m_keepRatioCheckBox->isChecked())
          {
              connect(sliderHeight, &QSlider::valueChanged, this, &MyClass::sliderHeightChanged);
              connect(sliderWidth, &QSlider::valueChanged, this, &MyClass::sliderWidthChanged);
          }
          
          ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #24

          @jsulm
          Are there other methods for resizing an Image?

          Maybe drag the Image in the Corners for resizing?

          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