Results 1 to 6 of 6

Thread: selected cells' table

  1. #1
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question selected cells' table

    How can i know how many rows span my selection in a table??

    Im my case, i have a qtexttable. When i select some cells, i'd like to know how many rows the selecion spans.......any idea???

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: selected cells' table

    Which widgets are you using? In general you can query for the item selection and you will be given all the selected indexes/items. Take a look at QItemSelection for example, there are some methods there that should work for you.

  3. #3
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: selected cells' table

    I use a QGraphicsTextItem Object filled with a QTextTable.
    I don't find any method of this class that i can use to obtain the specific behaviour.
    I think that the "mergeCells" function, inside it, makes the work i'm looking for.
    Qt Code:
    1. void QTextTable::mergeCells ( const QTextCursor & cursor )
    To copy to clipboard, switch view to plain text mode 

    ...infact, it just uses the reference to a QTextCursor Object to find out how many rows and columns the selection spans.

  4. #4
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: selected cells' table

    QGraphicsTextItem dont have the same qtextcursor selection as Qtextedit or QtextBrowser
    on version 4.2. on later version i not know...


    I rewrite the TextApi and run on this way....
    http://www.qt-apps.org/content/show....?content=80234

    Qt Code:
    1. void Layoutpainter::SetColumLarge()
    2. {
    3. if (textCursor().currentTable()) {
    4. QTextTableCell existingcell = textCursor().currentTable()->cellAt(textCursor());
    5. QTextTableFormat tbforms = textCursor().currentTable()->format();
    6. int cellcoolcursoris = existingcell.column(); /* int value start from zero */
    7. bool ok;
    8. int LargeSet = QInputDialog::getInteger(0, tr("Set Cell Width"),
    9. tr("Point Length:"),Get_Cell_Width(tbforms,cellcoolcursoris), 1, 2000, 1, &ok);
    10. if (ok && LargeSet > 0) {
    11. QVector<QTextLength> constraints = tbforms.columnWidthConstraints();
    12. for (int i = 0; i < constraints.size(); ++i) {
    13. if (i == cellcoolcursoris) {
    14. constraints.replace(i,QTextLength(QTextLength::FixedLength, LargeSet));
    15. }
    16. }
    17. tbforms.setColumnWidthConstraints(constraints);
    18. textCursor().currentTable()->setFormat(tbforms);
    19. }
    20. }
    21. }
    22.  
    23.  
    24. qreal Layoutpainter::Get_Cell_Width( QTextTableFormat TableFormat , int position )
    25. {
    26. qreal notfound = 0;
    27. QVector<QTextLength> constraints = TableFormat.columnWidthConstraints();
    28. for (int i = 0; i < constraints.size(); ++i) {
    29. if (i == position) {
    30. QTextLength langecell = constraints.value(i);
    31. if (langecell.type() == QTextLength::FixedLength) {
    32. return langecell.rawValue();
    33. }
    34.  
    35. }
    36. }
    37. return notfound;
    38. }
    39.  
    40. void Layoutpainter::MergeCellByCursorPosition()
    41. {
    42. if (textCursor().currentTable()) {
    43. textCursor().currentTable()->mergeCells(textCursor());
    44. }
    45. }
    46.  
    47.  
    48. void Layoutpainter::RemoveCoolByCursorPosition()
    49. {
    50. if (textCursor().currentTable()) {
    51. QTextTableCell existingcell = textCursor().currentTable()->cellAt(textCursor());
    52. int cellcoolcursoris = existingcell.column(); /* int value start from zero */
    53. int cellrowcursoris = existingcell.row(); /* int value start from zero */
    54. textCursor().currentTable()->removeColumns(cellcoolcursoris,1);
    55. }
    56. }
    57.  
    58. void Layoutpainter::RemoveRowByCursorPosition()
    59. {
    60. if (textCursor().currentTable()) {
    61. QTextTableCell existingcell = textCursor().currentTable()->cellAt(textCursor());
    62. int cellcoolcursoris = existingcell.column(); /* int value start from zero */
    63. int cellrowcursoris = existingcell.row(); /* int value start from zero */
    64. textCursor().currentTable()->removeRows(cellrowcursoris,1);
    65. }
    66. }
    67.  
    68.  
    69. void Layoutpainter::AppendTableRows()
    70. {
    71. bool ok = false;
    72. if (textCursor().currentTable()) {
    73. QTextTableCell existingcell = textCursor().currentTable()->cellAt(textCursor());
    74. int cellcoolcursoris = existingcell.column(); /* int value start from zero */
    75. int cellrowcursoris = existingcell.row(); /* int value start from zero */
    76. int approwtot = QInputDialog::getInteger(0, tr("Append NR. line row"),tr("Row:"), 1, 1, 100, 1, &ok);
    77. if (ok && approwtot > 0) {
    78. textCursor().currentTable()->insertRows(cellrowcursoris + 1,approwtot);
    79. }
    80. }
    81. }
    82.  
    83. void Layoutpainter::AppendTableCools()
    84. {
    85. bool ok = false;
    86. if (textCursor().currentTable()) {
    87. QTextTableCell existingcell = textCursor().currentTable()->cellAt(textCursor());
    88. int cellcoolcursoris = existingcell.column(); /* int value start from zero */
    89. int cellrowcursoris = existingcell.row(); /* int value start from zero */
    90. int appcooltot = QInputDialog::getInteger(0, tr("Table append Column"),tr("Cool:"), 1, 1, 10, 1, &ok);
    91. if (ok && appcooltot > 0) {
    92. textCursor().currentTable()->insertColumns(cellcoolcursoris + 1,appcooltot);
    93. }
    94. }
    95. }
    96.  
    97.  
    98. void Layoutpainter::SetTableCellColor()
    99. {
    100. if (textCursor().currentTable()) {
    101. bool ok;
    102. QTextTableCell existingcell = textCursor().currentTable()->cellAt(textCursor());
    103. /* reformat this -> existingcell */
    104. QTextCharFormat existformat = existingcell.format();
    105. /* get color */
    106. QColor col = QColorDialog::getRgba(textCursor().currentTable()->cellAt(textCursor()).format().background().color().rgba(),&ok, 0);
    107. if (!col.isValid()) {
    108. return;
    109. }
    110. QBrush stylesin(col);
    111. existformat.setBackground(stylesin);
    112. existingcell.setFormat(existformat);
    113. }
    114. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: selected cells' table

    anyone of these functions resolv my problem......

  6. #6
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Smile Re: selected cells' table

    problem resolved........here is the code!!

    Qt Code:
    1. int a,numrows,c,d;
    2. textCursor().selectedTableCells(&a,&numrows,&c,&d);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Showing selected rows in a separate table
    By dnnc in forum Qt Programming
    Replies: 3
    Last Post: 21st June 2007, 16:35
  2. Table and validating cells
    By zorro68 in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2007, 23:22
  3. table with combobox cells
    By mgurbuz in forum Qt Programming
    Replies: 2
    Last Post: 10th May 2006, 12:12
  4. displaying any table on a qdatatable
    By Philip_Anselmo in forum Newbie
    Replies: 4
    Last Post: 9th May 2006, 22:12
  5. Adding row in a Table after selected row
    By ankurjain in forum Qt Programming
    Replies: 3
    Last Post: 20th April 2006, 18:06

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.