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. Can I control enabled-ness of QComboBox from a QAbstractItemModel?

Can I control enabled-ness of QComboBox from a QAbstractItemModel?

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

    I have a class derived from QAbstractItemModel that is hooked up to a QComboBox. Is there a way to control the enabled-ness (setEnabled()) of the QComboBox from the model? My desire is that when there is only one item in the model, I want the QComboBox disabled, and if there is more than one item in the model, I want the QComboBox enabled.

    If I return Qt::ItemIsSelectable from flags(), the combobox is drawn with no selection (even though I have selected the one-and-only item) which is not what I want - I want the selected item to be drawn, but the combobox disabled (which is what I get if I call setEnabled() directly on the combobox).

    I can of course call setEnabled() from my code, bypassing the model, but I was hoping to find a way to do this that was more elegant.

    Thanks,
    Chris

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You could emit a custom signal from your model and emit it when you've reach the point of change (only one item, and more that one). Then connect that signal to QComboBox setEnabled

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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