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. Value from the "ScrollBar" for "switch"
Qt 6.11 is out! See what's new in the release blog

Value from the "ScrollBar" for "switch"

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 342 Views 1 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.
  • I Offline
    I Offline
    iSimstix1
    wrote on last edited by iSimstix1
    #1

    Hi!
    How to get value from the scroll bar for switch?

    oid MainWindow::on_pushButton_clicked()
    {
        
        ui->horizontalScrollBar->setRange(0, 8);
        
        switch(ui->horizontalScrollBar->value()){
        case ui->horizontalScrollBar->value(1): {
        
        }
        case ui->horizontalScrollBar->value(2): {
            
        }
    }
    
    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      Hi. case labels take constant expressions, so simply:

      switch(ui->horizontalScrollBar->value()) {
          case 1: {
          }
          case 2: {
          }        
      }
      

      Don't forget to put break; between those cases so you don't accidentaly fall through.

      1 Reply Last reply
      2

      • Login

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