Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7781159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:08:16+00:00 2026-06-01T19:08:16+00:00

Sorry for the vague title. Currently, if a value is typed into a Q(Double)SpinBox

  • 0

Sorry for the vague title.

Currently, if a value is typed into a Q(Double)SpinBox which is out of its range (e.g. typing “100” when max is 90), the value is rejected and instead the last valid value is placed back into the SpinBox.

I want to change this behavior to allow typing out-of-range values which will be automatically corrected (to either the minimum or maximum), because otherwise it would be stupidly hard for the user to guess the value range. After studying the docs and source code of QT, I decided to subclass QSpinBox (will deal with Double variant later) into “QSpinBoxFS”, and reimplement both methods mentioned in the title. Somehow though, this is having no effect at all, the behavior is still the same.

These are my methods:

QValidator::State QSpinBoxFS::validate(QString &input,
                                       int &pos)
{
    QIntValidator *validator = new QIntValidator();
    return validator->validate(input, pos);
}

int QSpinBoxFS::valueFromText(const QString &text)
{
    const int max = maximum();
    const int min = minimum();

    QString copy = text;
    int dummy = 0;

    QValidator::State state = validate(copy, dummy);

    if (state == QValidator::Acceptable)
    {
        bool ok;
        int num = locale().toInt(text, &ok, 10);
        if (!ok) { goto bad_text; }

        if (num < min) { return min; }
        if (num > max) { return max; }

        return num;
    }
    else
    {
        bad_text:
        return (max > 0) ? min : max;
    }
}

Of course, this is not really adequate to the pedantic checking done in QSpinBoxPrivate::validateAndInterpret, but I just want the basic concept working for now.
I tried changing validate() to always return Acceptable, but weirdly enough the resulting spinboxes would still behave in the old way.

Either a correction of my own methods or a different approach to this problem are welcome! Thank you for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:08:17+00:00Added an answer on June 1, 2026 at 7:08 pm

    The signatures of the methods you’re trying to reimplement are:

    QValidator::State validate(QString & input,int & pos) const # <- const!
    int valueFromText(const QString & text) const # <- const!
    

    Both your methods are missing the const, so they are different methods and thus never called from the base class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for vague question title, i couldn't figure out something more specific. I have
Sorry for the vague title, but this is kind of hard to put into
Sorry for the vague title, I can't really figure out another way to name
I'm sorry for a pretty vague title, didn't want to turn it into a
Sorry for vague question title. I've got a table containing huge list of, say,
Sorry for the vague title. Here's an example of what I'd like to do.
Sorry for the vague title, as I really can't explain this problem succinctly. Basically
Sorry about a vague title, but here's what i am trying to do. I
Sorry for such a vague title. Basically, I am trying to hack a function
Sorry for the long and yet still somehow vague title! A friend of mine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.