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. [Moved] How hard can it be to access a toolbar button and change it’s state via code?

[Moved] How hard can it be to access a toolbar button and change it’s state via code?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 5 Posters 3.9k 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.
  • D Offline
    D Offline
    DManel
    wrote on last edited by
    #1

    Hello everyone,

    So, I have a toolbar on my small program, with some buttons that I placed by hand on the UI with the design tool.
    I also created some triggering actions associated to them, so I can do other stuff by code.
    Now, I want to make the toolbar buttons checkable. So, if I'm doing something related to that button, is stays pressed, and then when I select another button, another action is triggered, and I want the previous button goes unchecked. Basically, I want one checked button at a time on my toolbar.

    How can I do this on my code? How can I access to a specific toolbar button on my code and change its state to unchecked?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      task_struct
      wrote on last edited by
      #2

      Hello,

      do you use Qt Components? There are already components that can to this for you - "ButtonRow"http://doc.qt.nokia.com/qt-components-symbian/qml-buttonrow.html and "ButtonColumn":http://doc.qt.nokia.com/qt-components-symbian/qml-buttoncolumn.html

      "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

      • Linu...
      1 Reply Last reply
      0
      • D Offline
        D Offline
        DManel
        wrote on last edited by
        #3

        Hi,

        No, I created and placed the buttons on the Designer (on the "mainWindow.ui" file by hand) and i setted some connections to work when clicked.

        But I want to make them checkable, in such a way that only the last one pressed remains checked...

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          Well, I guess you have chosen the wrong forum then. You are in Qt Quick, discussing mainly QML and JavaScript.

          As to your question: QAction has a checkable property, which makes the toolbutton checkable as well. If you want a set of acions to be exclusive add them to a QActionGroup.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mlong
            wrote on last edited by
            #5

            Moved this thread to General and Desktop

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              If you created your UI using Designer, then you can manipute all widgets on there using the same way you setup the connections. [[doc:QToolButton]] is a [[doc:QAbstractButton]], which has a property called checked. It seems logical to me that calling:
              @
              m_ui->myToolButton->setChecked(false);
              @
              would make sure your toolbutton is unchecked.

              However, I would certainly considder abstracting your actions in QActions instead. You can add QActions to your toolbar, and then manipulate the action instead of the tool button directly. This way, it is easier to offer the same action at multiple places simultaniously, and keep their state in sync. I often even expose functionality in my internal API as QActions, so I can bundle the information about the state of the action (it's availability for instance) and the action itself into one neat class.

              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