I create a button and put it in a cell of a table(QTableWidget),but I find that the currentRow of the table does not change when I click the button,how to do ?
I create a button and put it in a cell of a table(QTableWidget),but I find that the currentRow of the table does not change when I click the button,how to do ?
Last edited by weixj2003ld; 7th November 2011 at 02:55. Reason: sorry
No.
I explain my question.
1.I create a n*3 table(created with QTableWidget name table1);
2. I put buttons in the third column
3. When I click one of the buttons,I want to get the row of the button lies,
I use the follow signals,but it can not work well.
1.connect(button,signal(clicked()),this, signal(btnclicked()));
I find that table1->currRow() always does not change whenere I click what button.
When I click the cell in the first or second column,it is ok.
2. connect(table1,signal(cellclicked(int ,int)),signal(cellclickedslot(int ,int)));
it works like 1.
You cannot connect signal to signal.
Your code should be something like this:
See Signals & Slots documentationQt Code:
1. connect(button, SIGNAL(clicked()),this, SLOT(btnclicked())); 2. connect(table1, SIGNAL(cellclicked(int ,int)), SLOT(cellclickedslot(int ,int)));To copy to clipboard, switch view to plain text mode
Ok,that my error.
But,I have change the code as you said,and it still not work.
I think that,how to catch the signal cellclicked when I cklick the button,but I don't know how to do.
Signals can be connected to Signals, the problem in not related to this.
The problem is the mouse click event is taken by the button, and QTableWidget never receives it and hence cannot give current row information.
You need to associate each button with the row number, when you create the button. One way to do so is sub-class QPushButton and add a member variable (say buttonRow), and store the row number in it when you create the button. Now in the slot connected to clicked signal, check the member var.
Could you explain"check the member var"?
I sub-class QPushButton as follows:
and use it as follows:Qt Code:
{ public : private: int row; }To copy to clipboard, switch view to plain text mode
...
...Qt Code:
for(int i=0;i<count();i++) { .... myPushButton *myBtn=new myPushButton("convert",i); connect(myBtn,SIGNAL(clicked()),this,convertSlot()); } ... void TableMyclass::convertSlot() { how to check the row? }To copy to clipboard, switch view to plain text mode
Last edited by weixj2003ld; 10th November 2011 at 07:59. Reason: sorry
Take a look here:
http://developer.qt.nokia.com/forums/viewthread/5913
Connect clicked() signal to custom slot of your sub-classed QPushButton that emits new signal with the row variable and connect this new signal to convertSlot that can accept int variable.
Not sure if its the best solution but it should work.
Bookmarks