Results 1 to 2 of 2

Thread: add widget on a TableWidget error!

  1. #1
    Join Date
    May 2010
    Location
    China
    Posts
    66
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default add widget on a TableWidget error!

    i add a comobox on a TableWidget cells ,i used the for loop and the comobox only add on the last cell of the loop,and the others can't be edit! what's wrong ?


    Qt Code:
    1. table=new QTableWidget(50,50,this);
    2.  
    3.  
    4.  
    5. layou->addWidget(table);
    6.  
    7. setLayout(layou);
    8. QComboBox *combox=new QComboBox;
    9. combox->addItem("Text1",1);
    10. combox->addItem("Text2",1);
    11. combox->addItem("Text3",1);
    12. combox->addItem("Text4",1);
    13. combox->addItem("Text5",1);
    14. combox->addItem("Text6",1);
    15. combox->addItem("Text7",1);
    16.  
    17.  
    18.  
    19. for (int i=0;i<table->columnCount();i++)
    20. {
    21. table->setCellWidget(0,i,combox);
    22.  
    23. }T
    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: add widget on a TableWidget error!

    you are adding the same combobox again and again.
    You need to create a new combobox for each cell.
    ==========================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.

Similar Threads

  1. TableWidget
    By matulik in forum Newbie
    Replies: 6
    Last Post: 2nd May 2010, 18:47
  2. Custom widget plugin linker error
    By Annihilator in forum Qt Programming
    Replies: 0
    Last Post: 4th March 2010, 18:34
  3. Replies: 5
    Last Post: 21st February 2007, 22:11
  4. Error when promoting a custom widget
    By engin in forum Qt Tools
    Replies: 1
    Last Post: 15th December 2006, 16:00
  5. Error using kdebutton widget in QT
    By mysearch05 in forum Qt Programming
    Replies: 4
    Last Post: 8th February 2006, 18:50

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.