PDA

View Full Version : Problem with QT Treewidgetitem select.



keyurparekh
2nd February 2011, 06:31
Hi All,

I am beginner in qt. I need help to develop programme using QT. I am using current QT 4.6

I have created treewidget using QT designer. In this tree i have number of items. Now i want to connect only particular item with webpage. I have connect tree widget signal with webpage slot.

But when i click on any member of tree widget it will open same page.

I want that when i click on first item then only web page should open. other wise it should not respond. Below i am posting my code.


Source code


my3::my3(QWidget *parent, Qt::WindowFlags f ) :
QWidget(parent,f)
{
setupUi(this);
ui3 = new my4(this);
stackedWidget->addWidget(ui3);
___qtreewidgetitem1 = treeWidget->topLevelItem(0);

___qtreewidgetitem1->setText(0, "Biology");

QTreeWidgetItem *___qtreewidgetitem2 = ___qtreewidgetitem1->child(0);
___qtreewidgetitem2->setText(0, QApplication::translate("Form3", "Chapter 1", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem3 = treeWidget->topLevelItem(1);
___qtreewidgetitem3->setText(0, QApplication::translate("Form3", "New Item", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem4 = treeWidget->topLevelItem(2);
___qtreewidgetitem4->setText(0, QApplication::translate("Form3", "Chemistry", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem5 = treeWidget->topLevelItem(3);
___qtreewidgetitem5->setText(0, QApplication::translate("Form3", "Maths", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem6 = treeWidget->topLevelItem(4);
___qtreewidgetitem6->setText(0, QApplication::translate("Form3", "Database", 0, QApplication::UnicodeUTF8));


connect(treeWidget, SIGNAL( itemClicked(QTreeWidgetItem* ,int)),this, SLOT(open_webpage(QTreeWidgetItem*,int)));

}

void my3::open_webpage(QTreeWidgetItem *item,int column)
{
stackedWidget->setCurrentIndex( stackedWidget->indexOf(ui3));
}

I have posted my code. In that i have created class and one slot.

I have also connect tree widget with slot. But my problem is how can i connect particular item of tree with slot.

Please help me in this matter.

Thanks in advance.

tbscope
2nd February 2011, 06:44
Please add your code between code tags.

Why don't you use the item pointer in the slot? Using the item pointer, you can find out exactly which item is clicked.

By the way, your code is very ugly in my opinion.