Results 1 to 2 of 2

Thread: qtreewidget accessing data from another qtreewidget

  1. #1
    Join Date
    Apr 2007
    Posts
    7
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default qtreewidget accessing data from another qtreewidget

    Hello. This is not exactly my problem, I have simplified it but it should be worth.

    I have a QMainWindow with two QTreeWidgets.
    I have subclassed QTreeWidgets: MyTree1 and MyTree2, each one has its own ContextMenu when you right click on.

    Now I want to click on MyTree2 and in the ContextMenu I choose "Text of the first item" that it's used to debug and prints on console the text of the first QTreeWidgetItem of MyTree1.
    That should be too easy to do but since QMainWindow has a (QWidget)centralwidget and you can't remove it I don't know how to do that.

    It should be something like this:
    Qt Code:
    1. #include "mytree2.h"
    2.  
    3. MyTree2::MyTree2(QWidget* parent)
    4. : QTreeWidget(parent)
    5. {
    6. [...]
    7. p = parent->parentWidget(); //since p is a pointer
    8. //to the parent widget which is centralwidget
    9. //I also use parentWidget() to point to QMainWindow
    10. }
    11.  
    12. MyTree2::debugFirst()
    13. {
    14. qDebug() << p->QTreeWidget1->topLevelItem(0)->text(0);
    15. }
    To copy to clipboard, switch view to plain text mode 

    But an error compiling in line 14 says that Class QWidget doesnt own a member called QTreeWidget1

    So.. how could I do that?
    I hope you guys understand me and I'm sorry if this question is too newbie for the newbie forum

  2. #2
    Join Date
    Apr 2007
    Posts
    7
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qtreewidget accessing data from another qtreewidget

    Ok, I have found the solution.
    All what I needed is to declare the function as static and I had never used it.
    I found the answer in this forum but now I can't find the exact thread.

Similar Threads

  1. QTableView : accessing the data
    By marvaneke in forum Newbie
    Replies: 10
    Last Post: 30th March 2012, 11:31
  2. setting data of buffer to QTreeWidget column
    By thomasjoy in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2007, 17:12
  3. QTreeWidget - Parsing Data.
    By Preeteesh in forum Qt Programming
    Replies: 3
    Last Post: 17th June 2007, 12:57
  4. Accessing data from a worker thread
    By steg90 in forum Qt Programming
    Replies: 20
    Last Post: 25th May 2007, 10:20
  5. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.