Bin was Qt und die Programmierei angeht noch recht neu und hoffe ihr könnt mir erklären warum bei meinem Quelltext nicht das passiert, was ich davon erwarte
Wie der Titel schon verrät würde ich den User gerne durch einfaches Klicken auf einen Menüeintrag ein weiteres Tab öffnen/erstellen lassen. Soweit klappt auch alles ganz gut und die auf dem Eintrag liegende Funktion (heißen bei Qt ja QAction ist auch mit dem richtigen Slot connected). Dann sollen von der Slotfunktion addPlotTab() QWidgets erstellt werden, die dann via Ui_NewTab.setupUi() ein vorgefertigtes Layout und Child-Widgets (hier hab ich den Qt Designer benutzt) zugeteilt bekommen. Anschließen werden die neuen Widgets als Tabs via addTab() hinzugefügt.
Das Problem ist nun das sich diese Tabs aber leider nicht zeigen. Das Tabwidget behält beim Debuggen während immer nur den einen Standarttab mit dem es auch erzeugt wurde und die während der Laufzeit durch den User hinzugefügten Tags zeigen sich nicht.
Im Folgenden der code der mit Kopfschmerzen bereitet
mainwindowimpl.h
Code: Alles auswählen
#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();
};
#endifCode: Alles auswählen
#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);
//NewTab.show();
//tabWidget->setUpdatesEnabled(true);
tabWidget->addTab(&NewTab, name);
tabWidget->show();
//NewTab.show();
update();
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;
QPushButton *test;
test = new QPushButton(OldTab);
test->setObjectName(QString::fromUtf8("test"));
test->setGeometry(QRect(350, 20, 80, 27));
};Code: Alles auswählen
class Ui_PlotTab
{
public:
QGridLayout *gridLayout;
QVBoxLayout *verticalLayout_3;
QVBoxLayout *verticalLayout_2;
QHBoxLayout *horizontalLayout_2;
QLabel *label;
QLineEdit *lineEdit;
QHBoxLayout *horizontalLayout;
QGroupBox *groupBox;
QVBoxLayout *verticalLayout;
QCheckBox *checkBox;
QCheckBox *checkBox_2;
QPushButton *pushButton;
void setupUi(QWidget *PlotTab)
{
if (PlotTab->objectName().isEmpty())
PlotTab->setObjectName(QString::fromUtf8("PlotTab"));
PlotTab->resize(300, 164);
gridLayout = new QGridLayout(PlotTab);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
verticalLayout_3 = new QVBoxLayout();
verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3"));
verticalLayout_2 = new QVBoxLayout();
verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
horizontalLayout_2 = new QHBoxLayout();
horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
label = new QLabel(PlotTab);
label->setObjectName(QString::fromUtf8("label"));
horizontalLayout_2->addWidget(label);
lineEdit = new QLineEdit(PlotTab);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
horizontalLayout_2->addWidget(lineEdit);
verticalLayout_2->addLayout(horizontalLayout_2);
horizontalLayout = new QHBoxLayout();
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
groupBox = new QGroupBox(PlotTab);
groupBox->setObjectName(QString::fromUtf8("groupBox"));
horizontalLayout->addWidget(groupBox);
verticalLayout = new QVBoxLayout();
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
checkBox = new QCheckBox(PlotTab);
checkBox->setObjectName(QString::fromUtf8("checkBox"));
verticalLayout->addWidget(checkBox);
checkBox_2 = new QCheckBox(PlotTab);
checkBox_2->setObjectName(QString::fromUtf8("checkBox_2"));
verticalLayout->addWidget(checkBox_2);
horizontalLayout->addLayout(verticalLayout);
verticalLayout_2->addLayout(horizontalLayout);
verticalLayout_3->addLayout(verticalLayout_2);
pushButton = new QPushButton(PlotTab);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
verticalLayout_3->addWidget(pushButton);
gridLayout->addLayout(verticalLayout_3, 0, 0, 1, 1);
retranslateUi(PlotTab);
QMetaObject::connectSlotsByName(PlotTab);
} // setupUi
void retranslateUi(QWidget *PlotTab)
{
PlotTab->setWindowTitle(QApplication::translate("PlotTab", "Form", 0, QApplication::UnicodeUTF8));
label->setText(QApplication::translate("PlotTab", "Function", 0, QApplication::UnicodeUTF8));
groupBox->setTitle(QApplication::translate("PlotTab", "Settings", 0, QApplication::UnicodeUTF8));
checkBox->setText(QApplication::translate("PlotTab", "Logscale", 0, QApplication::UnicodeUTF8));
checkBox_2->setText(QApplication::translate("PlotTab", "LogLogscale", 0, QApplication::UnicodeUTF8));
pushButton->setText(QApplication::translate("PlotTab", "Plot", 0, QApplication::UnicodeUTF8));
Q_UNUSED(PlotTab);
} // retranslateUi
};