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. How to disable/grey QAction item text in Qt 4.8.4?
Forum Updated to NodeBB v4.3 + New Features

How to disable/grey QAction item text in Qt 4.8.4?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 4.6k 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
    jeevan_reddy
    wrote on last edited by
    #1

    Hi All,

    I am creating a QMenu with a set of QAction items as menuitems. My intention is to disable one of the menu items. I am using QAction's setEnabled(false) to disable the item but I find that the action item text is not greying out at all.
    @
    QMenu *contextual_menu = QMenu(this);
    QAction *car = contextual_menu ->addAction(QString("car"));
    QAction bus = contextual_menu ->addAction(QString("bus"));
    car->setEnabled(false);
    QAction
    selected_item = contextual_menu ->exec(QCursor::pos());
    @
    My expectation is that the action item "car" should be displayed in greyed state which is not happening, although clicking on it does not return the selected item but clicking on "bus" returns the selected item.
    Can smeone pls let me know whats the possible flaw in my code? I find it very amusing and baffling that such simple code didn't yield the desired result. any help is appreciated.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jeevan_reddy
      wrote on last edited by
      #2

      I have also tried the other way using the QMenu's aboutToShow() signal.
      @
      connect( contextual_menu, SIGNAL(aboutToShow()), this, SLOT(disableCarAction()) );

      SampleClass::disableCarAction()
      {
      car->setEnabled(false);
      }

      @

      My intention is to show one of the action items in greyed/disabled state when I click on a button which displays a contextual menu with a list of QAction item's.

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

        Hi,

        Can you provide a minimal sample code that allows to reproduce the problem ? Not just the QMenu part (which you already provided) but a widget that one can directly use to test

        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
        • J Offline
          J Offline
          jeevan_reddy
          wrote on last edited by
          #4

          Hi SGaist,

          The issue can be reproduced by creating a QPushButton on a QWidget and then connecting the button's signal clicked() to a slot called createContextualMenu(). In the slot method we can write the menu creation part with a set of QActions as menu items.

          I just used Qt Designer to create a Qwidget with a Qpushbutton in it.

          @
          QPushButton *more = new QPushButton();
          connect(more, SIGNAL( clicked()), this, SLOT( createContextualMenu());
          //this object can be any child of QWidget.

          MyCustomWidget::createContextualMenu()
          {
          //code present in previous post.
          }
          @

          so it is pretty straight forward approach, I was not trying anythg unusual .

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

            What os are you running on ? At least on OS X it's behaving correctly

            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
            • J Offline
              J Offline
              jeevan_reddy
              wrote on last edited by
              #6

              @SGaist - I'm using Windows 7 with Qt 4.8.4

              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