Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Toolbar's Action Disable Problem [SOLVED]

    General and Desktop
    4
    7
    3156
    Loading More Posts
    • 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
      kingsta last edited by

      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 Reply Quote 0
      • M
        mbnoimi last edited by

        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 Reply Quote 0
        • M
          mbnoimi last edited by

          don't forget to add:

          @filterAction->setCheckable(true);@

          1 Reply Last reply Reply Quote 0
          • raven-worx
            raven-worx Moderators last edited by

            @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 Reply Quote 0
            • K
              kingsta last edited by

              [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 Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                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 Reply Quote 0
                • K
                  kingsta last edited by

                  [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 Reply Quote 0
                  • First post
                    Last post