PDA

View Full Version : QlistWidget and StackedWidget



cpuinthebrain
22nd September 2012, 10:46
Hi,

i have QListWidget and QStackedWidget.
I want when select some item from the list to change the widget loaded in Stacked Widget.
Probably i should use currentIndex() signal in order to trigger the change.

Any ideas?

Zlatomir
22nd September 2012, 12:22
QListWidget has signals that give you both the new selected QListWidgetItem (http://qt-project.org/doc/qt-4.8/qlistwidget.html#currentItemChanged) and the new selected text (http://qt-project.org/doc/qt-4.8/qlistwidget.html#currentTextChanged) so you can use one of those (depending on your needs).

cpuinthebrain
22nd September 2012, 22:34
Thank you.
Is there any error in this, because it still doesn't work:

connect(ui->listWidget_settings, SIGNAL(currentTextChanged ( const QString & currentText )),this, SLOT(changeWidget()));

Zlatomir
23rd September 2012, 00:34
The connect statement is incorrect: you don't put signal/slot parameter name in the connect statement (so just const QString& remove currentText) and a second stuff is that most likely you would like the changeWidget() to take that string that changed in the QLisWidget and create/modify the widget accordingly with that QString: so you can create void changeWidget(const QString& changedText) (if you didn't put it now, don't forget to add public slots: access specifier) and use the text (changed from the QListWidget) into definition to create/update the widget so the connect will become:

connect(ui->listWidget_settings, SIGNAL(currentTextChanged ( const QString& )),this, SLOT(changeWidget(const QString&))); //at connect you write just the type of parameters

cpuinthebrain
24th September 2012, 19:10
Thank you!
Problem solved