Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Loop mathematics

    General and Desktop
    2
    5
    799
    Loading More Posts
    • 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.
    • D
      davidrhcp last edited by

      I got a combo box representing values from 50-90 in a combo.

      However the combo lists every value between those two numbers e.i. 50,51,52,53,54.....

      How can i modify my code to have the box only show multiples of 5.

      This is my code at the moment

      for (int i = 50; i < 91; i++)
      {
          ui->comboBox_Alert->addItem(QString::number(i) + "%");
      }
      
      1 Reply Last reply Reply Quote 0
      • M
        MuldeR last edited by

        I'd use a QSpinBox and setting the "singleStep" property accordingly.

        But if you want a Combobox, you could just modify your code like:
        @for (int i = 50; i <= 90; i += 5)
        {
        ui->comboBox_Alert->addItem(QString::number(i) + “%”);
        }@

        My OpenSource software at: http://muldersoft.com/

        Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

        Go visit the coop: http://youtu.be/Jay...

        1 Reply Last reply Reply Quote 0
        • D
          davidrhcp last edited by

          i'm using a combo box but i'm sure that shouldn't change much.

          I'm very beginner at this i would not know where to start implementing that command

          1 Reply Last reply Reply Quote 0
          • M
            MuldeR last edited by

            [quote author="davidrhcp" date="1399296936"]i'm using a combo box but i'm sure that shouldn't change much.[/quote]

            It does! The QSpinBox is made specifically for entering numbers. And it has a configurable “singleStep” property. Should be exactly what you need :-)

            See here:
            http://qt-project.org/doc/qt-4.8/qspinbox.html

            [quote author="davidrhcp" date="1399296936"]I'm very beginner at this i would not know where to start implementing that command[/quote]

            What command?

            My OpenSource software at: http://muldersoft.com/

            Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

            Go visit the coop: http://youtu.be/Jay...

            1 Reply Last reply Reply Quote 0
            • D
              davidrhcp last edited by

              thanks, was a great help :)

              1 Reply Last reply Reply Quote 0
              • First post
                Last post