Header
#ifndef ITEMDIALOG_H
#define ITEMDIALOG_H
//
#include "ui_dialog.h"
#include "ui_mainwindow.h"
#include "mainwindowimpl.h"
//
class itemdialog
: public QDialog,
public Ui
::Dialog{
Q_OBJECT
public:
private slots:
void additem();
private:
};
#endif
#ifndef ITEMDIALOG_H
#define ITEMDIALOG_H
//
#include "ui_dialog.h"
#include "ui_mainwindow.h"
#include "mainwindowimpl.h"
//
class QTreeWidget;
class itemdialog : public QDialog, public Ui::Dialog
{
Q_OBJECT
public:
itemdialog(QTreeWidget *m);
private slots:
void additem();
private:
QTreeWidget* mCallerTreeWidget;
};
#endif
To copy to clipboard, switch view to plain text mode
Implementation:
#include "itemdialog.h"
#include <QTreeWidget>
//
{
Ui_Dialog::setupUi(this);
mCallerTreeWidget = m;
connect(addButton, SIGNAL(clicked()), this, SLOT(additem()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
}
void itemdialog::additem()
{
// item->setText(0, nameEdit->text());
// item->setText(1, yearEdit->text());
item->setText(0, "abc");
item->setText(1, "1888");
mCallerTreeWidget->addTopLevelItem(item);
}
//
#include "itemdialog.h"
#include <QTreeWidget>
//
itemdialog::itemdialog(QTreeWidget *m )
: QDialog(m)
{
Ui_Dialog::setupUi(this);
mCallerTreeWidget = m;
connect(addButton, SIGNAL(clicked()), this, SLOT(additem()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
}
void itemdialog::additem()
{
QTreeWidgetItem *item = new QTreeWidgetItem(QTreeWidgetItem::Type);
// item->setText(0, nameEdit->text());
// item->setText(1, yearEdit->text());
item->setText(0, "abc");
item->setText(1, "1888");
mCallerTreeWidget->addTopLevelItem(item);
}
//
To copy to clipboard, switch view to plain text mode
Yes, it is bad to inherit from more than one UI. You had a QDialog andf a QMainWindow. They have to different event handlers, etc... So it is not ok .Also, you were always adding items to the same tree widget.
I modified a little bit your code and attached it.
You always must pass the tree widget which handled the context menu event.
Hey, didn't you said you have three tree widgets? I only saw one in the ui's...
Regards
Bookmarks