Hey Guys!
As you all can see I'm new to Qt and to this forum so please be patient with me ;-)
After playing around with a few tutorials I considered myself to be able to design a mainwindow-application that features dynamic tabs. That's means I want to allow the user to add a new instance of a predesigned tab while the program is running. I used the Qt Designer to build the forms. So here is my code, I hope you guys can help me. Thank you for your attention.
The QAction "actionNeues_PlotTab" is part of the menubar in the mainwindow and after compiling it runs correctly, means I get to read my qDebug messages. So it's basicly all about the addPlotTab() slot I guess. The Ui_PlotTab class is also something I generated with the Qt Designer and hopefully adds the right child-widgets to the one widget that will become my new tab.
Compiling doesn't make any trouble but when running and using the menubar entry that should reveal a new tab nothing happens although the new tabs seem to have an index.
mainwindowimpl.h
#ifndef MAINWINDOWIMPL_H
#define MAINWINDOWIMPL_H
//
#include <QMainWindow>
#include "ui_mainwindow.h"
//
class MainWindowImpl
: public QMainWindow,
public Ui
::MainWindow{
Q_OBJECT
public:
MainWindowImpl
( QWidget * parent
= 0, Qt
::WFlags f
= 0 );
private slots:
void addPlotTab();
};
#endif
#ifndef MAINWINDOWIMPL_H
#define MAINWINDOWIMPL_H
//
#include <QMainWindow>
#include "ui_mainwindow.h"
//
class MainWindowImpl : public QMainWindow, public Ui::MainWindow
{
Q_OBJECT
public:
MainWindowImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
private slots:
void addPlotTab();
};
#endif
To copy to clipboard, switch view to plain text mode
mainwindowimpl.cpp
#include "mainwindowimpl.h"
#include "ui_plottab.h"
#include <QtGui>
//
MainWindowImpl
::MainWindowImpl( QWidget * parent, Qt
::WFlags f
) {
setupUi(this);
connect(actionNeues_PlotTab, SIGNAL(activated()), this, SLOT(addPlotTab()));
}
//
void MainWindowImpl::addPlotTab()
{
Ui_PlotTab Ui_NewTab;
Ui_NewTab.setupUi(&NewTab);;
tabWidget->setUpdatesEnabled(true);
tabWidget->addTab(&NewTab, name);
int a = tabWidget->indexOf(&NewTab);
Ui_NewTab.setupUi(&NewTab2);
tabWidget->addTab(&NewTab2, name2);
int b = tabWidget->indexOf(&NewTab2);
qDebug() << "I'm still not working!" << a << "\t" << b;
};
#include "mainwindowimpl.h"
#include "ui_plottab.h"
#include <QtGui>
//
MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f)
: QMainWindow(parent, f)
{
setupUi(this);
connect(actionNeues_PlotTab, SIGNAL(activated()), this, SLOT(addPlotTab()));
}
//
void MainWindowImpl::addPlotTab()
{
QWidget NewTab;
QString name="NewTab";
Ui_PlotTab Ui_NewTab;
Ui_NewTab.setupUi(&NewTab);;
tabWidget->setUpdatesEnabled(true);
tabWidget->addTab(&NewTab, name);
int a = tabWidget->indexOf(&NewTab);
QWidget NewTab2;
QString name2="NewTab2";
Ui_NewTab.setupUi(&NewTab2);
tabWidget->addTab(&NewTab2, name2);
int b = tabWidget->indexOf(&NewTab2);
qDebug() << "I'm still not working!" << a << "\t" << b;
};
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QApplication>
#include "mainwindowimpl.h"
//
int main(int argc, char ** argv)
{
MainWindowImpl win;
win.show();
app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
return app.exec();
}
#include <QApplication>
#include "mainwindowimpl.h"
//
int main(int argc, char ** argv)
{
QApplication app( argc, argv );
MainWindowImpl win;
win.show();
app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks