Thank you for the quick response.Everything is ok now !
 thanks,
canal



________________________________
From: José Arcángel Salazar Delgado <arcangel.sala...@gmail.com>
To: qt-jambi-interest@trolltech.com
Sent: Thu, September 30, 2010 12:47:02 PM
Subject: Re: [Qt-jambi-interest] to determine which button is clicked in the 
signal/slot

On Mié 29 Sep 2010 23:28:53 go canal escribió:
> Thank you.
> Here is my code - first I create a tab with a '+' button; when click the
> '+' button, insert a new tab which has a 'x' button for removing the tab.
> The code works - I can capture the signal and determine which tab; but
> strange though, I capture two signals for one click. I have no idea why:
> 
> public class MyTab extends QTabWidget {
> public MyTab (QWidget parent) {
> super (parent);
> initialize();
> }
> 
> // create the home page with the '+' button.
> private void initialize() {
> QWidget homePage = new QWidget();
> this.insertTab (0, homePage, "Home");
> QPushButton plusButton = new QPushButton("+");
> plusButton.setMaximumWidth (30);
> plusButton.clicked.connect (this, "addTab()");
> this.tabBar().setTabButton (0, ButtonPosition.RightSide, plusButton);
> signalMapper = new QSignalMapper (this);
> }
> private void addTab () {
> QWidget page = new QWidget();
> this.insertTab(1, page, "New Page");
> // add a 'x' button
> QPushButton deleteButton = new QPushButton("x");
> deleteButton.setMaximumWidth(30);
> this.tabBar().setTabButton(1, ButtonPosition.RightSide, deleteButton);
> 
> deleteButton.clicked.connect(signalMapper, "map()");
> signalMapper.setMapping(deleteButton, (QObject)page);

Here is the problem. The conecction with the signal mapper  is repeated 
multiples times. If you have two tabs, you create two connections. 
Make this connection in the initialize method.  

signalMapper.mappedQObject.connect(this, "deleteTab(QObject)"); 



> }
> // this is called twice, why ???
> private void deleteTab (QObject page) {
> if (page != null && page instanceof QWidget) {
> int index = this.indexOf ((QWidget)page);
> System.out.println ("delete tab " + index);
> }
> }
> 
> 
> }
>  thanks,
> canal
> 
> 
> 
> 
> ________________________________
> From: José Arcángel Salazar Delgado <arcangel.sala...@gmail.com>
> To: qt-jambi-interest@trolltech.com
> Sent: Wed, September 29, 2010 10:52:59 PM
> Subject: Re: [Qt-jambi-interest] to determine which button is clicked in
> the signal/slot
> 
> On Mié 29 Sep 2010 00:41:56 go canal escribió:
> > Hi,
> > a newbie question and sorry if it was asked before, I googled it but have
> > not find good answer:
> > 
> > I have a tab widget, a few tabs, each tab has a close button. When I
> > clicked the close button, I want to remove the tab. Question is, how do I
> > know which button is clicked in the connection:
> > 
> > public class MyTab extends QTabWidget {
> > ......
> > 
> > private void addTab () {
> > QPushButton deleteButton = new QPushButton("x");
> > deleteButton.setMaximumWidth(30);
> > tabBar.insertTab (1, "New Page");
> > tabBar.setTabButton(1, ButtonPosition.RightSide, deleteButton);
> > deleteButton.clicked.connect(this, "deleteTab()");
> > }
> > private void deleteTab () {
> > // how do we know which button is clicked, and which tab I should remove
> > ? }
> 
> Hello.
> 
> You have two options. One if to use the signalSender method to obtaind the
> object that emit the signal that triggers the slot. Two is to use the
> QSignalMapper class to map the all the signal y one slot.
> 
> > }
> > 
> >  thanks,
> > 
> > canal
> 
> _______________________________________________
> Qt-jambi-interest mailing list
> Qt-jambi-interest@trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest

_______________________________________________
Qt-jambi-interest mailing list
Qt-jambi-interest@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest



      
_______________________________________________
Qt-jambi-interest mailing list
Qt-jambi-interest@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest

Reply via email to