[SOLVED] QAction ToolButton in toolbar triggered should open a TabWidget
-
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. -
Hi,
What do you mean by open ? Something like a dialog ? Show a specific widget in a QTabWidget ?
-
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 -
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 ?
-
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? -
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
-
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 :)
-
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);
}
@ -
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.-
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);
}@ -
on my mainwindow.h these were declared:
@private slots:
void on_actionA_triggered();@- 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.
-