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] QAction ToolButton in toolbar triggered should open a TabWidget
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QAction ToolButton in toolbar triggered should open a TabWidget

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 3.8k 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.
  • A Offline
    A Offline
    angelicaP
    wrote on last edited by
    #1

    hi,

    i checked everything related to this, but no too many posts found; actually nothing relevant.
    only "here":http://qt-project.org/forums/viewthread/15781 i found something similar, but is not pointing anywhere.

    i have a ToolButton in my toolbar and when is triggered I would like to open a TabWidget.
    where shall i start?
    thanks for your input.

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

      Hi,

      What do you mean by open ? Something like a dialog ? Show a specific widget in a QTabWidget ?

      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
      • A Offline
        A Offline
        angelicaP
        wrote on last edited by
        #3

        Something like a dialog showing a new form in the QTabWidget. the form is created on a separate .ui file, but this TabWidget should be part of the Mainwindow, not a new window.

        makes sense? or shall i return with more details.
        thanks

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

          If I understand you correctly:

          • You have a QTabWidget as your central widget in your QMainWindow
          • When you click on the button, you would like to have a new widget show on the QTabWidget ?

          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
          • A Offline
            A Offline
            angelicaP
            wrote on last edited by
            #5

            no,
            thanks for your prompt reply.

            let's start again: I have my MainWindow, with a Toolbar, on this Toolbar I have a ToolButton. I want to trigger this button and open on a QTabWidget my form, which is a separate .ui file.

            when i created the ToolButton, the action was created. What class i need to initiate to have this QTabWidget opened, if I 'Go to Slot' of the created action ?

            this QTabWidget I'd like to be part of the MainWindow, not a new window.
            how it should be done?

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

              Then what you describe is indeed having a QTabWidget as your QMainWindow central widget.

              Add a slot in your MainWindow that will create a new tab in your QTabWidget using the ui file

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

                basic start:

                i'm trying to declare the addTab syntax for a test, before I will integrate my .ui form, which I think would replace the QWidget in this structure.

                based on the syntax:
                @QTabWidget::addTab ( QWidget * child, const QString & label )@

                i'm struggling to find out what this pointer *child is, or how to write correctly the "const QString & label" part.

                don't get mad, please, I'm trying to learn :)

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

                  Have a look at the QTabWidget doc and associated example.

                  child is the widget you would like to add to your QTabeWidget and label is the name that will appear on the tab.

                  Simple dummy example:
                  @
                  MainWindow::MainWindow(QWidget *parent) :
                  QMainWindow(parent)
                  {
                  QLabel *label = new QLabel(tr("Showing a label in a QTabWidget"));
                  QTabWidget *tabWidget = new QTabWidget;
                  tabWidget->addTab(label, tr("Test Widget"));
                  setCentralWidget(tabWidget);
                  }
                  @

                  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
                  • A Offline
                    A Offline
                    angelicaP
                    wrote on last edited by
                    #9

                    hi SGaist,
                    you made my day.
                    i'm back to say thank you and to public my solution, maybe somebody else will be interested in the future in this issue. as i mentioned in my previous post, I have my MainWindow, with a Toolbar, on this Toolbar I have a ToolButton. When the ToolButton is triggered the action will open on a QTabWidget my form, which is a separate .ui file.

                    1. on my mainwindow.cpp:
                      @#include "aA.h" //my separated aA.ui form
                      ...
                      void MainWindow::on_actionA_triggered()
                      {
                      connect(ui->actionA, SIGNAL(triggered()), this, SLOT(actionA_triggered()));
                      QTabWidget *tabWidget = new QTabWidget;
                      addA * aA = new addA ();
                      tabWidget->addTab(aA, tr("Test Label"));
                      setCentralWidget(tabWidget);
                      }@

                    2. on my mainwindow.h these were declared:

                    @private slots:
                    void on_actionA_triggered();@

                    1. the separated form is called aA.ui, and has a header file aA.h

                    i hope this is useful. for me works.

                    all the best.

                    ps: if you consider that some comments should be added, please don't hesitate; or if you have another simpler solution, please add it.

                    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