PDA

View Full Version : List Widget



sabbu
3rd May 2011, 09:01
how to go one screen to another screen.i want when i select the listwidget item then open new window please any one can help me .

Thanks

qlands
3rd May 2011, 14:21
Hi,

You can connect the signal void itemClicked ( QListWidgetItem * item ) to an slot in the parent window (the window where your list is).

This signal is emitted with the specified item when a mouse button is clicked on an item in the widget.

For example:

You declare a slot called callWindow in the .h of the parent window:


private slots:
void callWindow(QListWidgetItem * item);


Then you connect the signal of the list to that slot somewhere in the code of the parent window, in the constructor for example:



connect(ui->mylist,SIGNAL(itemClicked ( QListWidgetItem * item )),this,SLOT( callWindow(QListWidgetItem * item))


The connection passes a pointer to the selected item. So you can access its data. For example its caption.

So in the c++ of the parent window you have:



void MainWindow::callWindow(QListWidgetItem * item)
{
//Here you call the other window
}


With this when the user clicks on the item it calls the slot so it can call your new window.