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. [solved] qtoolbar and qstackwidget
Forum Updated to NodeBB v4.3 + New Features

[solved] qtoolbar and qstackwidget

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.4k 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.
  • B Offline
    B Offline
    broadpeak
    wrote on last edited by
    #1

    I have a toolbar with icons at the left. I'd like to change the "perspective" on the mainwindow when I click on a toolbar icon.
    But:
    toolbar icon has only signal triggered or triggered(bool) and qstackwidget has only slot setCurrentIndex(int).
    Of course this is not working :)

    Any idea for replacement of qstackwidget? Or some solution?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      rcari
      wrote on last edited by
      #2

      You should use a "QSignalMapper":http://qt-project.org/doc/qt-4.8/qsignalmapper.html

      1 Reply Last reply
      0
      • B Offline
        B Offline
        broadpeak
        wrote on last edited by
        #3

        [quote author="rcari" date="1344942978"]You should use a "QSignalMapper":http://qt-project.org/doc/qt-4.8/qsignalmapper.html[/quote]

        Can you send me a code snippet how can I solve this?
        In this case the QSignalMapper is not clear me.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rcari
          wrote on last edited by
          #4

          This should do:
          @#include <QtGui/QtGui>

          int main(int argc, char** argv)
          {
          QApplication app(argc, argv);

          QMainWindow mw;
          mw.setMinimumSize(400,300);
          mw.show();
          mw.raise();

          QSignalMapper mapper;

          QToolBar* tb = new QToolBar();

          QAction* tab;
          tab = tb->addAction(QObject::tr("Tab 1"));
          mapper.setMapping(tab, 0);
          mapper.connect(tab, SIGNAL(triggered(bool)), SLOT(map()));

          tab = tb->addAction(QObject::tr("Tab 2"));
          mapper.setMapping(tab, 1);
          mapper.connect(tab, SIGNAL(triggered(bool)), SLOT(map()));

          tab = tb->addAction(QObject::tr("Tab 3"));
          mapper.setMapping(tab, 2);
          mapper.connect(tab, SIGNAL(triggered(bool)), SLOT(map()));

          mw.addToolBar(Qt::TopToolBarArea, tb);

          QStackedWidget* stack = new QStackedWidget;
          QLabel* lbl;
          lbl = new QLabel(QObject::tr("TAB 1"));
          lbl->setAlignment(Qt::AlignCenter);
          stack->addWidget(lbl); // index: 0
          lbl = new QLabel(QObject::tr("TAB 2"));
          lbl->setAlignment(Qt::AlignCenter);
          stack->addWidget(lbl); // index: 1
          lbl = new QLabel(QObject::tr("TAB 3"));
          lbl->setAlignment(Qt::AlignCenter);
          stack->addWidget(lbl); // index: 2
          // Connect the mapper
          stack->connect(&mapper, SIGNAL(mapped(int)), SLOT(setCurrentIndex(int)));

          mw.setCentralWidget(stack);

          return app.exec();
          }@

          1 Reply Last reply
          0
          • B Offline
            B Offline
            broadpeak
            wrote on last edited by
            #5

            Ohhh! I big thank for you!!! :)

            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