Change StackedWidget Pages With TreeWidget
-
wrote on 31 May 2016, 17:35 last edited by
Hello,
I Have a StackedWidget and TreeWidget in my Window
I Want to Connect this Two Object,
And I Wrote This Codes But None Of This Codes Worked!
My Codes:#include "management_menu.h" #include "ui_management_menu.h" management_menu::management_menu(QWidget *parent) : QWidget(parent), ui(new Ui::management_menu) { ui->setupUi(this); connect(ui->lineEdit,SIGNAL(textChanged(QString)),this,SLOT(onTextChanged())); connect(ui->treeWidget,SIGNAL(itemActivated(QTreeWidgetItem*,int)),ui->stackedWidget,SLOT(setCurrentIndex(int))); connect(ui->treeWidget,SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),ui->stackedWidget,SLOT(setCurrentIndex(int))); connect(ui->treeWidget,SIGNAL(itemChanged(QTreeWidgetItem*,int)),ui->stackedWidget,SLOT(setCurrentIndex(int))); connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem*,int)),ui->stackedWidget,SLOT(setCurrentIndex(int))); } management_menu::~management_menu() { delete ui; }
What i must do?
-
Hello,
I Have a StackedWidget and TreeWidget in my Window
I Want to Connect this Two Object,
And I Wrote This Codes But None Of This Codes Worked!
My Codes:#include "management_menu.h" #include "ui_management_menu.h" management_menu::management_menu(QWidget *parent) : QWidget(parent), ui(new Ui::management_menu) { ui->setupUi(this); connect(ui->lineEdit,SIGNAL(textChanged(QString)),this,SLOT(onTextChanged())); connect(ui->treeWidget,SIGNAL(itemActivated(QTreeWidgetItem*,int)),ui->stackedWidget,SLOT(setCurrentIndex(int))); connect(ui->treeWidget,SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),ui->stackedWidget,SLOT(setCurrentIndex(int))); connect(ui->treeWidget,SIGNAL(itemChanged(QTreeWidgetItem*,int)),ui->stackedWidget,SLOT(setCurrentIndex(int))); connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem*,int)),ui->stackedWidget,SLOT(setCurrentIndex(int))); } management_menu::~management_menu() { delete ui; }
What i must do?
wrote on 31 May 2016, 18:12 last edited bythe signal and slot parameter does not match. Try to write your own slot then call stackwidget methods.
example :
connect(ui->treeWidget,SIGNAL(itemActivated(QTreeWidgetItem*,int)), this, SLOT(myslot(QTreeWidgetItem*,int))); in my slot: void management_menu::mySlot(QTreeWidgetItem*,int index) { ui->stackedWidget->setCurrentIndex(index); }
This should work.
-
the signal and slot parameter does not match. Try to write your own slot then call stackwidget methods.
example :
connect(ui->treeWidget,SIGNAL(itemActivated(QTreeWidgetItem*,int)), this, SLOT(myslot(QTreeWidgetItem*,int))); in my slot: void management_menu::mySlot(QTreeWidgetItem*,int index) { ui->stackedWidget->setCurrentIndex(index); }
This should work.
-
wrote on 31 May 2016, 18:44 last edited by
Yes, you are right it will work only one timer because, itemActivated(QTreeWidgetItem*,int), the second parameter is column id. So this will be same for the entire column.
One way to do is that set some information to QTreeWidgetItem and in myslot use this information to call stackedWidget methods.
QTreeWidgetItem *s = new QTreeWidgetItem(); // set data s->setData(0, Qt::UserRole, QVariant("1")); // obtain data QVariant data = s->data(0, Qt::UserRole);
-
wrote on 31 May 2016, 18:47 last edited by
You may want to see this example
http://doc.qt.io/qt-5/qtwidgets-dialogs-configdialog-example.html
4/5