Results 1 to 3 of 3

Thread: how can i get the QPushButton clicked on a QTable

  1. #1
    Join Date
    Mar 2011
    Posts
    2
    Qt products
    Qt Jambi
    Platforms
    Windows

    Default how can i get the QPushButton clicked on a QTable

    Hello,
    I explain my problem and I hope that someone may give me the solution.

    Currently I am developing a small application with graphical interfaces and that with Java and Qt

    So I create a QTable (a table) and within each line there are QLabels for text and a button that emits a signal.

    My table is composed of several lines and therefore more buttons, I want to know what is the button that issued the last signal or in other words which button was clicked.

    I searched the web for a few hours but no way because the solution is either in C + + and I can not transcribe it in java or I have not found the solution.

    thank you

    Qt Code:
    1. public class PrecoMur {
    2.  
    3. QTableWidget table = new QTableWidget(0,7);
    4.  
    5. private QVBoxLayout glayout = new QVBoxLayout();
    6.  
    7. ArrayList data=FenetrePrincipale.mursEdit.getNomsMurs();
    8. ArrayList data1=FenetrePrincipale.mursEdit.getEpaisseursMurs();
    9. ArrayList data2=FenetrePrincipale.mursEdit.getSurfacesMurs();
    10. ArrayList data3=FenetrePrincipale.mursEdit.getReMurs();
    11.  
    12. ArrayList <PrecoMurB> qg=new ArrayList <PrecoMurB> ();
    13.  
    14. //constructeur
    15. public PrecoMur()
    16. {
    17.  
    18. ArrayList<String> labels = new ArrayList<String>();
    19. labels.add("Nom");
    20. labels.add("Surface");
    21. labels.add("Epaisseur");
    22. labels.add("Re");
    23. labels.add("Preco");
    24. labels.add("Modifier");
    25. labels.add("");
    26. table.setHorizontalHeaderLabels(labels);
    27. table.setGridStyle(Qt.PenStyle.NoPen);
    28. table.setAlternatingRowColors(true);
    29. this.qg=addLigne();
    30. glayout.addWidget(table);
    31.  
    32.  
    33. for (int i=0;i<qg.size();i++)
    34. {
    35.  
    36. qg.get(i).p.clicked.connect(this, "preconiser()");
    37. qg.get(i).m.clicked.connect(this,"modifier()");
    38.  
    39. }
    40.  
    41.  
    42.  
    43.  
    44. //insérer le tableau dans la groupbox infospreco
    45. Preconisations.gb.setLayout(glayout);
    46.  
    47. }
    48.  
    49. private ArrayList addLigne() {
    50. // TODO Auto-generated method stub
    51. table.setRowCount(data.size());
    52. ArrayList q= new ArrayList ();
    53. for (int i=0;i<data.size();i++)
    54. {
    55. QPushButton fairepreco=new QPushButton("Préconiser");
    56. QPushButton modifierpreco=new QPushButton("Modifier");
    57.  
    58. c.setEnabled(false);
    59. modifierpreco.setMaximumHeight(20);
    60. modifierpreco.setMinimumHeight(20);
    61. modifierpreco.setMaximumWidth(50);
    62. modifierpreco.setMinimumWidth(50);
    63.  
    64. PrecoMurB b=new PrecoMurB(fairepreco,modifierpreco,c,i);
    65.  
    66. table.setCellWidget(i, 0, new QLabel((String) data.get(i)));
    67. table.setCellWidget(i, 2, new QLabel(data1.get(i)+" cm"));
    68. table.setCellWidget(i, 1, new QLabel(data2.get(i)+" m²"));
    69. table.setCellWidget(i, 3, new QLabel(data3.get(i)+" K.m²/W"));
    70. table.setCellWidget(i, 4, b.p);
    71. table.setCellWidget(i, 5, b.m);
    72. table.setCellWidget(i, 6, b.c);
    73.  
    74.  
    75. q.add(b);
    76. }
    77. table.update();
    78. return q;
    79. }
    80.  
    81.  
    82. public void preconiser()
    83. {
    84. System.out.println("AAAA");
    85. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how can i get the QPushButton clicked on a QTable

    Have a look at QObejct::sender().
    You might want to have a look at QSignalMapper.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Mar 2011
    Posts
    2
    Qt products
    Qt Jambi
    Platforms
    Windows

    Default Re: how can i get the QPushButton clicked on a QTable

    hello,

    I looked and QSignalMapper sender but I did not know how
    Could you help me because I code in Java not C + +

Similar Threads

  1. QLabel::clicked()
    By sabeesh in forum Qt Programming
    Replies: 16
    Last Post: 1st August 2012, 03:17
  2. Qpushbutton clicked()
    By sasori1512 in forum Qt Programming
    Replies: 3
    Last Post: 20th February 2011, 02:03
  3. Replies: 0
    Last Post: 22nd February 2010, 09:30
  4. QPushButton color when clicked
    By ntp in forum Qt Programming
    Replies: 3
    Last Post: 30th April 2008, 18:34
  5. Replies: 3
    Last Post: 26th September 2006, 12:16

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.