Results 1 to 3 of 3

Thread: QTableWidget span !

  1. #1
    Join Date
    Oct 2008
    Posts
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTableWidget span !

    Hello Guys,

    I'm new to the forum, I really admire the effort you guys put on this and I wish I could take part of it.


    I have been struggling with this for about a week now, and still couldnt figure out the right way to doing it.

    Here is an example version:

    Qt Code:
    1. #include <QApplication>
    2. #include <QTableWidget>
    3.  
    4.  
    5.  
    6. ////////////////////Class Definition////////////////////
    7. class Table: public QTableWidget
    8. {
    9.  
    10. public:
    11. Table(QWidget *parent=0);
    12. void addRowAndMerge(int, int, int);
    13.  
    14. enum {MaxRows=100, MaxColumns=4};
    15. };
    16.  
    17.  
    18. ////////////////////Implementation////////////////////
    19. Table::Table(QWidget *parent): QTableWidget(parent)
    20. {
    21. setRowCount(MaxRows);
    22. setColumnCount(MaxColumns);
    23.  
    24. }
    25.  
    26. //append a nLines line at the end of row and span
    27. void Table::addRowAndMerge(int nLines, int row, int column)
    28. {
    29. int _insertedRows;
    30.  
    31. _insertedRows = rowSpan(row, column); // how many already spanned rows
    32.  
    33. for (int i = 0; i < nLines; i++) { //insert
    34. insertRow(row + _insertedRows + i);
    35. }
    36.  
    37. setSpan(row, column, _insertedRows + nLines-1, 1); //span
    38. }
    39.  
    40.  
    41. ////////////////////Test////////////////////
    42. int main(int argc, char *argv[])
    43. {
    44. QApplication app(argc, argv);
    45.  
    46. Table *tab = new Table;
    47. tab->addRowAndMerge(2, 2, 0); // insert 2 lines at (2, 0)
    48. tab->addRowAndMerge(3, 0, 0); // insert 3 lines at (0, 0)
    49. tab->show();
    50.  
    51. return app.exec();
    52. }
    To copy to clipboard, switch view to plain text mode 



    The proble is as follows:

    Suppose I insert 2 lines after the second line and span the cell at (2,0) to 2.
    Now if I insert exactly 3 lines or more at position 0 and span the cell at (0,0) to 3,
    everything is ruined up, the result is Horrible !!!

    Please if you can suggest me any other way to manage it correctly, I'll be really very Thankfull.

  2. #2
    Join Date
    Oct 2008
    Posts
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableWidget span !

    I Suppose it's a bug what can you say ?

    Please can I have some indications

  3. #3
    Join Date
    Oct 2008
    Posts
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableWidget span !

    Resolved !!

    Ive just installed QtX11 4.4.3 it did save my life.
    A new function was introduced called clearSpans()

    so before adding any row, I save old span informations in a temprorary buffer, I call clearSpans(), insert line and restore old infos.

    If you are encountering the same probleme, here is it resolved

  4. The following user says thank you to stephanyShulter for this useful post:

    dark_banishing (7th December 2008)

Similar Threads

  1. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 14th October 2007, 00:29
  2. Select columns from a QTableWidget
    By toglez in forum Qt Programming
    Replies: 10
    Last Post: 7th October 2007, 16:15
  3. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 19:46
  4. QTableWidget with overlapping cells (span)
    By rhi in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2006, 19:44
  5. Replies: 6
    Last Post: 5th March 2006, 22:05

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.