Results 1 to 2 of 2

Thread: connecting ComboBox with TreeWidget

  1. #1
    Join Date
    Dec 2010
    Location
    Lithuania
    Posts
    29
    Qt products
    Qt4
    Platforms
    Windows

    Default connecting ComboBox with TreeWidget

    Hi,

    I need to connect spin box, push button and tree widget together. I made that pretty easy while it's on the same widget but I need to show tree widget in another widget.

    Can anyone tell me. I tried to connect it. I thought I made it. No errors but then it simple stops working :/

    I connected widget where the push button was and widget where tree widget should appear.

    any ideas?

    by the way. what it means setbuddy?

  2. #2
    Join Date
    Dec 2010
    Location
    Lithuania
    Posts
    29
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: connecting ComboBox with TreeWidget

    When I connecting everything on the same widget I am using this slot

    Qt Code:
    1. void CreatePlanet::applyButtonClicked()
    2. {
    3. treeW->clear();
    4. QList<QTreeWidgetItem *> items;
    5. for (int i = 1; i < sizeSpinbox->value()+1; ++i)
    6. items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("dwelling: %1").arg(i))));
    7. treeW->insertTopLevelItems(0, items);
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

    but when i am trying to separate it:

    createplanet.cpp
    Qt Code:
    1. signals:
    2. void spinBoxValue(int);
    3. public slots:
    4. void applyButtonClicked ();
    To copy to clipboard, switch view to plain text mode 

    createplanet.cpp
    Qt Code:
    1. void CreatePlanet::applyButtonClicked()
    2. {
    3. treeW->clear();
    4. QList<QTreeWidgetItem *> items;
    5. for (int i = 1; i < sizeSpinbox->value()+1; ++i)
    6. items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("dwelling: %1").arg(i))));
    7. treeW->insertTopLevelItems(0, items);
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

    tree.h
    Qt Code:
    1. public:
    2. Tree(QWidget *parent = 0);
    3. QTreeWidget *treeW;
    4. signals:
    5.  
    6. public slots:
    7. private slots:
    8. void setNumber(int);
    To copy to clipboard, switch view to plain text mode 
    tree.cpp
    Qt Code:
    1. Tree::Tree(QWidget *parent) :
    2. QWidget(parent)
    3. {
    4. treeW = new QTreeWidget(this);
    5. treeW->setColumnCount(2);
    6. QStringList headers;
    7. headers << "Dwelling" << "Type";
    8. treeW->setHeaderLabels(headers);
    9.  
    10.  
    11.  
    12. grdLayout = new QGridLayout(this);
    13.  
    14. grdLayout->addWidget(treeW,0,0,1,1);
    15. this->setLayout(grdLayout);
    16. }
    17. void Tree::setNumber(int inum)
    18. {
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 

    mainwidget.cpp
    Qt Code:
    1. CreatePlanet *viewPlanetWidget = new CreatePlanet(createViewport);
    2. createViewport->addWidget(viewPlanetWidget);
    3. dwellingsTreeViewport = new QStackedWidget(this);
    4. Tree *dwellingsTree = new Tree(dwellingsTreeViewport);
    5.  
    6. dwellingsTreeViewport->addWidget(dwellingsTree);
    7. connect(viewPlanetWidget,SIGNAL(spinBoxValue(int)),dwellingsTree,SLOT(setNumber(int)));
    To copy to clipboard, switch view to plain text mode 


    what could I add into setNumbet(int) slot?

    Is correct way to connect different class objects?

Similar Threads

  1. Replies: 2
    Last Post: 18th May 2010, 22:44
  2. How to add subitem in treewidget
    By phillip_Qt in forum Qt Programming
    Replies: 11
    Last Post: 16th November 2009, 11:22
  3. FTP recursive treeWidget
    By Aji Enrico in forum Qt Programming
    Replies: 2
    Last Post: 12th April 2008, 11:26
  4. Filtering a TreeWidget
    By soul_rebel in forum Qt Programming
    Replies: 6
    Last Post: 26th January 2008, 20:08
  5. Painting TreeWidget
    By VireX in forum Qt Programming
    Replies: 9
    Last Post: 9th May 2007, 08:36

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.