PDA

View Full Version : connecting ComboBox with TreeWidget



Shien
26th December 2010, 10:23
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?

Shien
26th December 2010, 12:30
When I connecting everything on the same widget I am using this slot


void CreatePlanet::applyButtonClicked()
{
treeW->clear();
QList<QTreeWidgetItem *> items;
for (int i = 1; i < sizeSpinbox->value()+1; ++i)
items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("dwelling: %1").arg(i))));
treeW->insertTopLevelItems(0, items);

}

but when i am trying to separate it:

createplanet.cpp

signals:
void spinBoxValue(int);
public slots:
void applyButtonClicked ();

createplanet.cpp

void CreatePlanet::applyButtonClicked()
{
treeW->clear();
QList<QTreeWidgetItem *> items;
for (int i = 1; i < sizeSpinbox->value()+1; ++i)
items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("dwelling: %1").arg(i))));
treeW->insertTopLevelItems(0, items);

}


tree.h

public:
Tree(QWidget *parent = 0);
QTreeWidget *treeW;
signals:

public slots:
private slots:
void setNumber(int);

tree.cpp

Tree::Tree(QWidget *parent) :
QWidget(parent)
{
treeW = new QTreeWidget(this);
treeW->setColumnCount(2);
QStringList headers;
headers << "Dwelling" << "Type";
treeW->setHeaderLabels(headers);



grdLayout = new QGridLayout(this);

grdLayout->addWidget(treeW,0,0,1,1);
this->setLayout(grdLayout);
}
void Tree::setNumber(int inum)
{

}

mainwidget.cpp

CreatePlanet *viewPlanetWidget = new CreatePlanet(createViewport);
createViewport->addWidget(viewPlanetWidget);
dwellingsTreeViewport = new QStackedWidget(this);
Tree *dwellingsTree = new Tree(dwellingsTreeViewport);

dwellingsTreeViewport->addWidget(dwellingsTree);
connect(viewPlanetWidget,SIGNAL(spinBoxValue(int)) ,dwellingsTree,SLOT(setNumber(int)));



what could I add into setNumbet(int) slot?

Is correct way to connect different class objects?