Results 1 to 2 of 2

Thread: Problem with QT Treewidgetitem select.

  1. #1
    Join Date
    Feb 2011
    Posts
    29
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Problem with QT Treewidgetitem select.

    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

    Qt Code:
    1. my3::my3(QWidget *parent, Qt::WindowFlags f ) :
    2. QWidget(parent,f)
    3. {
    4. setupUi(this);
    5. ui3 = new my4(this);
    6. stackedWidget->addWidget(ui3);
    7. ___qtreewidgetitem1 = treeWidget->topLevelItem(0);
    8.  
    9. ___qtreewidgetitem1->setText(0, "Biology");
    10.  
    11. QTreeWidgetItem *___qtreewidgetitem2 = ___qtreewidgetitem1->child(0);
    12. ___qtreewidgetitem2->setText(0, QApplication::translate("Form3", "Chapter 1", 0, QApplication::UnicodeUTF8));
    13. QTreeWidgetItem *___qtreewidgetitem3 = treeWidget->topLevelItem(1);
    14. ___qtreewidgetitem3->setText(0, QApplication::translate("Form3", "New Item", 0, QApplication::UnicodeUTF8));
    15. QTreeWidgetItem *___qtreewidgetitem4 = treeWidget->topLevelItem(2);
    16. ___qtreewidgetitem4->setText(0, QApplication::translate("Form3", "Chemistry", 0, QApplication::UnicodeUTF8));
    17. QTreeWidgetItem *___qtreewidgetitem5 = treeWidget->topLevelItem(3);
    18. ___qtreewidgetitem5->setText(0, QApplication::translate("Form3", "Maths", 0, QApplication::UnicodeUTF8));
    19. QTreeWidgetItem *___qtreewidgetitem6 = treeWidget->topLevelItem(4);
    20. ___qtreewidgetitem6->setText(0, QApplication::translate("Form3", "Database", 0, QApplication::UnicodeUTF8));
    21.  
    22.  
    23. connect(treeWidget, SIGNAL( itemClicked(QTreeWidgetItem* ,int)),this, SLOT(open_webpage(QTreeWidgetItem*,int)));
    24.  
    25. }
    26.  
    27. void my3::open_webpage(QTreeWidgetItem *item,int column)
    28. {
    29. stackedWidget->setCurrentIndex( stackedWidget->indexOf(ui3));
    30. }
    To copy to clipboard, switch view to plain text mode 
    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.
    Last edited by Lykurg; 2nd February 2011 at 06:43. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Problem with QT Treewidgetitem select.

    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.

Similar Threads

  1. How to write TreewidgetItem validations
    By mkkguru in forum Qt Programming
    Replies: 0
    Last Post: 1st February 2010, 11:19
  2. Button in TreeWidgetItem
    By osiris81 in forum Qt Programming
    Replies: 3
    Last Post: 16th June 2009, 12:58
  3. toolTip of TreeWidgetItem display is slow
    By yunpeng880 in forum Qt Programming
    Replies: 0
    Last Post: 9th March 2009, 09:35
  4. a question about drag treewidgetItem
    By Alina in forum Qt Programming
    Replies: 2
    Last Post: 15th March 2006, 08:40
  5. a simple question .how to delete a treewidgetitem
    By Alina in forum Qt Programming
    Replies: 6
    Last Post: 20th February 2006, 10:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.