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 Item Disable
Forum Updated to NodeBB v4.3 + New Features

QComboBox Item Disable

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 15.4k 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.
  • G Offline
    G Offline
    GreenFire
    wrote on last edited by
    #1

    I am trying to disable certain items in a QComboBox when a user selects a certain item from another QComboBox is there an easy way of doing this?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      The proper way of doing this would be to provide a custom model for combo box and clear the ItemIsSelectable and ItemIsEnabled flags for the items you want to disable.

      If you're not afraid of undocumented hacks that can break at any given point in the future there's also "this dirty dirty trick":http://theworldwideinternet.blogspot.com/2011/01/disabling-qcombobox-items.html based on current internal implementation of default model:
      @
      // disable item
      ui->comboBox->setItemData(index, 0, Qt::UserRole - 1);
      // enable item
      ui->comboBox->setItemData(index, 33, Qt::UserRole - 1);
      @

      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