Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QToolbar first item not clickable?
Qt 6.12 LTS is out! See what's new in the release blog

QToolbar first item not clickable?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 4.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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Very very weird issue. I've got code for a GUI I'm working on, and whatever action I add as the first item in the QToolbar is not clickable like usual.

    So, when I do this:

    @
    //----- Set up the top toolbar
    QToolBar* pToolBar = addToolBar("Connections");
    pToolBar->setObjectName("ConnectionBar");

    _pConnectAction = pToolBar->addAction("Connect");

    connect(_pConnectAction, SIGNAL(triggered()),
    this, SLOT(connectToServer()));
    @

    I get a QAction, which I cannot click, like this:

    !http://i.imgur.com/yhk87Lq.png()!

    When I add another QAction in front, like this:

    @
    QToolBar* pToolBar = addToolBar("Connections");
    pToolBar->setObjectName("ConnectionBar");

    pToolBar->addAction("foo you");

    _pConnectAction = pToolBar->addAction("Connect");

    connect(_pConnectAction, SIGNAL(triggered()),
    this, SLOT(connectToServer()));
    @

    I get this (notice that now Connect is clickable)

    !http://i.imgur.com/AHNyhax.png()!

    This is running in a QMainWindow subclass constructor.

    What have I done wrong?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      also, not sure why the images didn't just come inline.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Why are you passing a string parameter to the addAction method? The method has the following signature:

        void addAction(QAction *action);

        You should create an action first, then add it to a toolbar. Try something like this:

        @
        QAction *deleteAction = new QAction(QIcon(":/images/delete.png"), tr("&Delete"), this);
        deleteAction->setShortcut(tr("Delete"));
        deleteAction->setStatusTip(tr("Delete item from diagram"));
        connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem()));

         QToolBar *editToolBar = addToolBar(tr("Edit"));
         editToolBar->addAction(deleteAction);
        

        @

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Um, there is an overloaded version of addAction that makes the QAction for you?

          http://qt-project.org/doc/qt-4.8/qtoolbar.html#addAction-2

          Shouldn't have to make it first, then add it. The overload should work fine, and in fact does so for the second item.

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            Yep, you're right. Haven't seen it, sorry about that.

            This is strange indeed. Which version are you using? I just ran this simple test and it worked perfectly, with Qt 5.0.1 on Linux.

            @
            class MainWindow : public QMainWindow
            {
            Q_OBJECT

            public:
            MainWindow(QWidget *parent = 0);
            virtual ~MainWindow();

            (...)

            private slots:
            void testPrintRun();
            void testPrintStop();

            private:
            void createToolBars();

            QToolBar *toolbar;
            QAction *run;
            QAction *stop;
            (...)
            

            };

            (...)

            void MainWindow::createToolBars()
            {
            toolBar = addToolBar(tr("Run toolbar"));
            toolBar->setObjectName("run_toolbar");

            run = toolBar->addAction("runAct");
            stop = toolBar->addAction("stopAct");
            
            connect(run, SIGNAL(triggered()),
                    this, SLOT(testPrintRun()));
            
            connect(stop, SIGNAL(triggered()),
                    this, SLOT(testPrintStop()));
            

            }

            void MainWindow::testPrintRun()
            {
            std::cout << "Run action clicked" << std::endl;
            }

            void MainWindow::testPrintStop()
            {
            std::cout << "Stop action clicked" << std::endl;
            }

            @

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              I'm on Qt 4.8.3 on Ubuntu 12.10. I'll have to find a few minutes to run that code.

              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
              • Unsolved