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. How to override the QDoubleSpinbox StepBy function
Qt 6.11 is out! See what's new in the release blog

How to override the QDoubleSpinbox StepBy function

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 775 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.
  • S Offline
    S Offline
    summit
    wrote on last edited by Christian Ehrlicher
    #1

    I am overriding the StepBy function of QDoubleSpinBox

    // override to adjust step size
    void SumDoubleBox::stepBy(int steps)
    {
    	
    	(steps > 0.0 ? m_stepUp = true : m_stepUp = false);
    	// set the actual step size here
    	double newStep = m_defaultStep;
    	
    
    	if (QApplication::queryKeyboardModifiers() & Qt::ShiftModifier & Qt::ControlModifier )
    		newStep *= 0.01;
    	else if (QApplication::queryKeyboardModifiers() & Qt::ShiftModifier)
    		newStep *= 0.1;
    	
    	// be sure to call the base setSingleStep() here, otherwise redundant loop.
    	m_CurrentStep = newStep * steps;
    	QDoubleSpinBox::setSingleStep(newStep);
    	QDoubleSpinBox::stepBy(steps);
    }
    

    The function works fine but somehow this condition never gets executed

    if (QApplication::queryKeyboardModifiers() & Qt::ShiftModifier & Qt::ControlModifier )
    

    when the user presses both shift and Control button the Doublespinbox increments by default value 1

    Christian EhrlicherC 1 Reply Last reply
    0
    • S summit

      I am overriding the StepBy function of QDoubleSpinBox

      // override to adjust step size
      void SumDoubleBox::stepBy(int steps)
      {
      	
      	(steps > 0.0 ? m_stepUp = true : m_stepUp = false);
      	// set the actual step size here
      	double newStep = m_defaultStep;
      	
      
      	if (QApplication::queryKeyboardModifiers() & Qt::ShiftModifier & Qt::ControlModifier )
      		newStep *= 0.01;
      	else if (QApplication::queryKeyboardModifiers() & Qt::ShiftModifier)
      		newStep *= 0.1;
      	
      	// be sure to call the base setSingleStep() here, otherwise redundant loop.
      	m_CurrentStep = newStep * steps;
      	QDoubleSpinBox::setSingleStep(newStep);
      	QDoubleSpinBox::stepBy(steps);
      }
      

      The function works fine but somehow this condition never gets executed

      if (QApplication::queryKeyboardModifiers() & Qt::ShiftModifier & Qt::ControlModifier )
      

      when the user presses both shift and Control button the Doublespinbox increments by default value 1

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @summit said in How to override the QDoubleSpinbox StepBy function:

      & Qt::ShiftModifier & Qt::ControlModifier

      This is wrong. If you want to check both conditions you have to use 'or' instead binary and

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      4

      • Login

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