Results 1 to 9 of 9

Thread: distinguish which qtreewidget called a slot

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: distinguish which qtreewidget called a slot

    Header
    Qt Code:
    1. #ifndef ITEMDIALOG_H
    2. #define ITEMDIALOG_H
    3. //
    4. #include "ui_dialog.h"
    5. #include "ui_mainwindow.h"
    6. #include "mainwindowimpl.h"
    7. //
    8.  
    9.  
    10. class itemdialog : public QDialog, public Ui::Dialog
    11. {
    12. Q_OBJECT
    13. public:
    14. itemdialog(QTreeWidget *m);
    15.  
    16. private slots:
    17. void additem();
    18.  
    19. private:
    20. QTreeWidget* mCallerTreeWidget;
    21.  
    22. };
    23. #endif
    To copy to clipboard, switch view to plain text mode 

    Implementation:
    Qt Code:
    1. #include "itemdialog.h"
    2. #include <QTreeWidget>
    3. //
    4. itemdialog::itemdialog(QTreeWidget *m )
    5. : QDialog(m)
    6. {
    7. Ui_Dialog::setupUi(this);
    8. mCallerTreeWidget = m;
    9. connect(addButton, SIGNAL(clicked()), this, SLOT(additem()));
    10. connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
    11. }
    12.  
    13. void itemdialog::additem()
    14. {
    15. // item->setText(0, nameEdit->text());
    16. // item->setText(1, yearEdit->text());
    17. item->setText(0, "abc");
    18. item->setText(1, "1888");
    19.  
    20. mCallerTreeWidget->addTopLevelItem(item);
    21. }
    22. //
    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

  2. The following user says thank you to marcel for this useful post:

    MurDoK (1st May 2007)

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

    Default Re: distinguish which qtreewidget called a slot

    Hey, I got it working!
    Hey, didn't you said you have three tree widgets? I only saw one in the ui's...
    Yes, but I only wanted to get a working example of it. Now I have implemented it in my project

    So.. thanks marcel, you rule! This has been a nice welcome to the qtcentre forums for me. See you.

Similar Threads

  1. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32

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.