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. Is there a way to distinguish between programmatic index changes and user selection index changes?
Forum Update on Tuesday, May 27th 2025

Is there a way to distinguish between programmatic index changes and user selection index changes?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.0k 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.
  • J Offline
    J Offline
    jmalicke
    wrote on 11 Jul 2014, 04:30 last edited by
    #1

    I have a QComboBox. I have two use cases. In one use case, the combo box is programmatically changed to have a new index via setCurrentIndex(). In the other use case, the user clicks and selects a new combo box selection with the mouse.

    Both of these use cases trigger the QComboBox::currentIndexChanged(int) signal. This is a major problem for the code I am trying to port. In the old framework (not Qt), a similar callback mechanism would be called only if the user selected an item and not if the index programmatically changed.

    How can I mimic this behavior in Qt?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on 11 Jul 2014, 04:49 last edited by
      #2

      I think you need to combine "void QComboBox::activated(int index)":http://qt-project.org/doc/qt-5/qcombobox.html#activated signal and a knowledge of a current index.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        poorBob
        wrote on 11 Jul 2014, 06:35 last edited by
        #3

        Hello,

        maybe when You call setCurrentIndex() You can use "QObject::blockSignals":http://qt-project.org/doc/qt-4.8/qobject.html#blockSignals method to disable emitting the QComboBox::currentIndexChanged(int) signal?

        Here's a little code how to do it:
        @pCombo->blockSignals(true);
        pCombo->setCurrentIndex(1);
        pCombo->blockSignals(false); // important to enable signals
        @

        I used this solution some time ago for similar situation and it works perfectly.

        with best regards,
        poorBob

        1 Reply Last reply
        0

        1/3

        11 Jul 2014, 04:30

        • Login

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