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. QComboBox menu, set Option menu from Variable
Forum Updated to NodeBB v4.3 + New Features

QComboBox menu, set Option menu from Variable

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.1k 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.
  • yczoY Offline
    yczoY Offline
    yczo
    wrote on last edited by
    #1

    Hi, I have the next QComboBox menu:

    QComboBox *Mode = new QComboBox(this);
    Mode->addItem(tr("Off"));
    Mode->addItem(tr("Manual"));
    Mode->addItem(tr("Automatic"));
    

    The default option shown is "Off", the question is: How can I change the menu selected with a a varaible... it is possible?

    my idea is : if(num == 3) Mode->setMenu(Automatic);

    Any help will be wellcomed.

    Thanks in advance

    Joel BodenmannJ 1 Reply Last reply
    0
    • yczoY yczo

      Hi, I have the next QComboBox menu:

      QComboBox *Mode = new QComboBox(this);
      Mode->addItem(tr("Off"));
      Mode->addItem(tr("Manual"));
      Mode->addItem(tr("Automatic"));
      

      The default option shown is "Off", the question is: How can I change the menu selected with a a varaible... it is possible?

      my idea is : if(num == 3) Mode->setMenu(Automatic);

      Any help will be wellcomed.

      Thanks in advance

      Joel BodenmannJ Offline
      Joel BodenmannJ Offline
      Joel Bodenmann
      wrote on last edited by Joel Bodenmann
      #2

      The easiest way will be to use QComboBox::setCurrentIndex(int index).
      Note that indexes start with 0, not with 1. So in your case "Automatic" would have index 2.

      QComboBox::setCurrentText() was added somewhen after Qt 4.8 if that helps in your case.

      Hope that helps.

      Industrial process automation software: https://simulton.com
      Embedded Graphics & GUI library: https://ugfx.io

      1 Reply Last reply
      1
      • T Offline
        T Offline
        thEClaw
        wrote on last edited by
        #3

        QComboBox::setCurrentIndex() should be what you are looking for. Unless I misunderstood you.

        1 Reply Last reply
        1
        • yczoY Offline
          yczoY Offline
          yczo
          wrote on last edited by
          #4

          Thank you very much! That was!

          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