Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
Posts: 16
Registered: ‎01-17-2013
My Device: None
My Carrier: None
Accepted Solution

How do you change the visibility of DropDown after it's created?

I'm creating a QML document with three DropDown lists.  Depending on how "trans_type" is selected, only one additional DropDown should be displayed.  If the "account" option is selected, the Account DropDown is visible and the Category DD is hidden.  The opposite is true if the "category" option is selected.

 

Here's how I'm building my QML document:

void Testing::updateFields()
{
    if (m_form.isNull())
        return;

    // Clear all fields from the form
    m_form->removeAll();

    // Clear the internal mapping
    m_fields.clear();

	//get the transaction page ready
	QmlDocument *qml = QmlDocument::create("asset:///transaction.qml").parent(this);

	DropDown* trans_type = qml->createRootObject<DropDown>();
	trans_type = DropDown::create().title("Transaction Type");
	trans_type->add(Option::create().text("Accounts").value("0"));
	trans_type->add(Option::create().text("Categories").value("1"));
	trans_type->setSelectedIndex(0);
	connect(trans_type, SIGNAL(selectedIndexChanged (int)), this, SLOT(onDDChange(int)));
	m_form->add(trans_type);

	DropDown* account_dd = qml->createRootObject<DropDown>();
	account_dd = DropDown::create().title("Account");
	account_dd->add(Option::create().text("No Account").value("0"));
	//... code to populate account drop down here...
	account_dd->setSelectedIndex(0);
	m_form->add(account_dd);

	DropDown* category_dd = qml->createRootObject<DropDown>();
	category_dd = DropDown::create().title("Category").visible(false);
	category_dd->add(Option::create().text("No Category").value("0"));
	//... code to populate category drop down here...
	category_dd->setSelectedIndex(0);
	m_form->add(category_dd);

}

 Everything shows up correctly on the page.  onDDChange gets called and it shows a Toast of which option was selected.  Here's what I currently have in onDDChange:

void Testing::onDDChange(const int &info)
{
	QString msg = "Switched To: ";
	if(info == 0) {
		msg = msg + "Account";
	} else if(info==1) {
		msg = msg + "Category";
	} else {
		msg = msg + "Unrecognized";
	}
	showToast(msg);
}

 

I can't figure out how to get the dropdown lists to be visible/hidden as needed.  There's a "setVisible()" function for the DropDown but I can't figure out how to get it to work without the app crashing.  http://developer.blackberry.com/cascades/reference/bb__cascades__dropdown.html#function-setvisible-v...

 

My questions are:

 

1. How can I change the visibility of the appropriate drop down lists in a different function when the status of the main dropdown list is changed?

 

2. Is there a way to set an id for the dropdown lists?  If not, how am I supposed to get the dropdown lists into a variable later so I can get their value or change the visibility?

 

Any help would be great.  I've been struggling with this for a while.

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: How do you change the visibility of DropDown after it's created?

There are a number of methods you could use signals and slots between your code and the QML or something simpler is assign 'objectName' as a property then look this up in C++.

 

http://developer.blackberry.com/cascades/documentation/dev/integrating_cpp_qml/

 

Something like

 

 

DropBox db = mRootContainer->findChild<DropBox*>("dropboxname");
db->setVisible(true);

 

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Contributor
Posts: 16
Registered: ‎01-17-2013
My Device: None
My Carrier: None

Re: How do you change the visibility of DropDown after it's created?

I don't see any methods for setting an objectName when creating the elements as I am through c++. Am i missing something?
Highlighted
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: How do you change the visibility of DropDown after it's created?

[ Edited ]

It's in every QObject derived control...

 

http://developer.blackberry.com/cascades/reference/qobject.html

 

 

 

DropDown::create()
    .title("Category")
    .visible(false)
    .objectName("dropdown");

 

Are you aware of the Ctrl+Space feature in Momentics (eclipse) which does autocompletion this can be helpful for finding which Builder properties are or are not available.

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.