You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

Shien

Beginner

  • "Shien" is male
  • "Shien" started this thread

Posts: 15

Location: Lithuania

Occupation: Studying

  • Send private message

1

Saturday, December 25th 2010, 11:03am

how to connect tree widget and combo box

Hi,
can anyone tell me how to connect tree widget and combo box?

What I mean is that when I choose number n form combo box and push PushButton then automatically tree list forms with n branches.

Can anyone tell me how to do this?

Thanks
p.s. merry Christmas

tomasstr

Beginner

  • "tomasstr" is male

Posts: 35

Location: Vilnius, Lithuania

  • Send private message

2

Saturday, December 25th 2010, 12:23pm

You have to:
1. Connect push signal of your button to some slot (function) which will be adding items to QTreeWidget.
2. This slot (function) will be reading currently selected text from combobox (to get the count of tree branches to be created).
3. This slot (function) will be clearing all items in the QTreeWidget and then adding required amount of items to QTreeWidget. Documentation of QTreeWidget gives examples on how to add new items.

Shien

Beginner

  • "Shien" is male
  • "Shien" started this thread

Posts: 15

Location: Lithuania

Occupation: Studying

  • Send private message

3

Saturday, December 25th 2010, 12:30pm

thanks

This post has been edited 1 times, last edit by "Shien" (Dec 25th 2010, 9:07pm)


Shien

Beginner

  • "Shien" is male
  • "Shien" started this thread

Posts: 15

Location: Lithuania

Occupation: Studying

  • Send private message

4

Saturday, December 25th 2010, 9:10pm

Now I am simple testing QPushButton. I am trying simple by clicking push button get number of spin box into QLabel. I done it. But only in the same class. In order to succeed I need to transfer it to another class. I found some examples how to do it but there goes errors:

p:3: error: redefinition of 'Tree::Tree(QWidget*)'
Tree::Tree(QWidget*)' previously defined here

and the code:
#ifndef CREATEPLANET_H
#define CREATEPLANET_H

#include <QtGui>

class CreatePlanet : public QWidget
{
Q_OBJECT
private:

QGridLayout *grdLayout;

public:
explicit CreatePlanet(QWidget *parent = 0);
QSpinBox *sizeSpinbox;
QLabel *lbl;
signals:
void spinBoxValue(int);
public slots:
void applyButtonClicked ();

};

#endif // CREATEPLANET_H


#include "createplanet.h"

CreatePlanet::CreatePlanet(QWidget *parent) :
QWidget(parent)
{
QLabel *planetNameLabel = new QLabel("Name of planet:",this);
QLineEdit *planetNameEdit = new QLineEdit();
QLabel *sizeLabel = new QLabel("Select size of the planet:");
sizeSpinbox = new QSpinBox(this);
sizeSpinbox->setRange(1,7);



QPushButton *applySizeButton = new QPushButton("Apply",this);
connect(applySizeButton,SIGNAL(clicked()),this,SLOT(applyButtonClicked()));

// lbl = new QLabel("skaicius:",this);

grdLayout = new QGridLayout(this);


grdLayout->addWidget(planetNameLabel,0,0,1,1);
grdLayout->addWidget(planetNameEdit,0,1,1,2);
grdLayout->addWidget(sizeLabel,1,0,1,1);
grdLayout->addWidget(sizeSpinbox,1,1,1,1);
grdLayout->addWidget(applySizeButton,2,0,1,1);
// grdLayout->addWidget(lbl,3,0,1,1);
this ->setLayout(grdLayout);
}

void CreatePlanet::applyButtonClicked()
{
lbl->setNum(sizeSpinbox->value());
emit spinBoxValue(sizeSpinbox->value());
}

#ifndef TREE_H
#define TREE_H

#include <QtGui>
#include "createplanet.h"

class Tree : public QWidget
{
Q_OBJECT
private:
CreatePlanet createplanet;
QLabel *lbl;
QGridLayout *grdLayout;
public:
Tree(QWidget *parent = 0)
{
connect(&createplanet,SIGNAL(spinBoxValue(int)),this,SLOT(setNumberLabel(int)));
}

signals:

public slots:
private slots:
void setNumberLabel(int inum)
{
lbl->setNum(inum);
}

};

#endif // TREE_H

This post has been edited 1 times, last edit by "Shien" (Dec 26th 2010, 9:33am)


Shien

Beginner

  • "Shien" is male
  • "Shien" started this thread

Posts: 15

Location: Lithuania

Occupation: Studying

  • Send private message

5

Sunday, December 26th 2010, 9:35am

I managed to connect all parts I need on the same widget. But in order to succeed I need that Tree widget would be in different widget.

Any ideas how to do that?