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. Loop mathematics
Forum Update on Monday, May 27th 2025

Loop mathematics

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 996 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.
  • D Offline
    D Offline
    davidrhcp
    wrote on last edited by
    #1

    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
    0
    • M Offline
      M Offline
      MuldeR
      wrote on last edited by
      #2

      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
      0
      • D Offline
        D Offline
        davidrhcp
        wrote on last edited by
        #3

        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
        0
        • M Offline
          M Offline
          MuldeR
          wrote on last edited by
          #4

          [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
          0
          • D Offline
            D Offline
            davidrhcp
            wrote on last edited by
            #5

            thanks, was a great help :)

            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