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. Toolbar's Action Disable Problem [SOLVED]
QtWS25 Last Chance

Toolbar's Action Disable Problem [SOLVED]

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 3.8k Views
  • 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.
  • K Offline
    K Offline
    kingsta
    wrote on last edited by
    #1

    Hello guys.

    I want to disable a toolbar button sometimes. I mean toolbar button is unclickable and visible. I look for the internet but I cant find the solution.

    This code crush my program.
    @filterAction->setEnabled(false);@

    createActions()
    @filterAction = new QAction(tr("&Filter Data"), this);
    filterAction->setIcon(QIcon("filter.ico"));
    connect(filterAction, SIGNAL(triggered()), this, SLOT(filterData()));
    ...
    @

    createToolbars()
    @QToolBar *toolbar;
    toolbar = addToolBar(tr("Processes"));
    toolbar->addAction(filterAction);
    ...
    @

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbnoimi
      wrote on last edited by
      #2

      I suggest to use this instead:

      @connect(filterAction, SIGNAL(triggered(bool)), this, SLOT(filterData()));@

      and this conection for the slot:

      @if (checked)
      filterAction->setEnabled(true);
      else
      filterAction->setEnabled(false);@

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mbnoimi
        wrote on last edited by
        #3

        don't forget to add:

        @filterAction->setCheckable(true);@

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @mbnoimi:
          He wanted to know how to "disable ":http://qt-project.org/doc/qt-4.8/qaction.html#enabled-propan action not to make it checkable. So i think this is not what the intended.

          [quote author="kingsta" date="1367141772"]
          This code crush my program.
          @filterAction->setEnabled(false);
          [/quote]
          What do you mean with "crush"? You program crashes when you do this? If so make sure that the pointer has been already initialized.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kingsta
            wrote on last edited by
            #5

            [quote author="mbnoimi" date="1367142196"]I suggest to use this instead:

            @connect(filterAction, SIGNAL(triggered(bool)), this, SLOT(filterData()));@
            [/quote]

            Okey. I changed the code. I dont know the different between triggered() and triggered(bool). Can you tell to me?

            [quote author="raven-worx" date="1367143959"]
            What do you mean with "crush"? You program crashes when you do this? If so make sure that the pointer has been already initialized.
            [/quote]

            You totally right. I realize I have a pointer problem. I fix it. It works.

            I have a question. How can i connect the toolbar view changing?
            I write that code but I got the message;
            @ QObject::connect: Cannot connect (null)::visibilityChanged(bool) to MainWindow::controlToolBarView()@

            code
            @ connect(toolbar, SIGNAL(visibilityChanged(bool)), this, SLOT(controlToolBarView()));
            @

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

              triggered(bool) is for when your tool button is checkable. The parameter tells you where you checked it (true) or unchecked it.

              The error message says that your connecting a NULL pointer. Are you sure you toolbar variable points to a valid QToolbar when calling connect ?

              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
              • K Offline
                K Offline
                kingsta
                wrote on last edited by
                #7

                [quote author="SGaist" date="1367185839"]triggered(bool) is for when your tool button is checkable. The parameter tells you where you checked it (true) or unchecked it.

                The error message says that your connecting a NULL pointer. Are you sure you toolbar variable points to a valid QToolbar when calling connect ?[/quote]
                You right. I fix the error.

                Thank all of you guys.

                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