Results 1 to 2 of 2

Thread: QTableWidget swapping rows with widgets in cells

  1. #1
    Join Date
    Oct 2006
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTableWidget swapping rows with widgets in cells

    Hi to all,
    This is my first post, although I have followed this forum for some time and resolved many problems thanks to it.

    I have a one column QTableWidget with each cell in a row containing a QwtPlot inside. I want to move up/down a plot in the table, so instead of using removeRow and insertRow, because the former deletes the plot inside the cell, I used in Qt 4.1.0 the following (simplified) code which works, given that setCellWidget just overrides the previous widget with the new one without deleting the previous one.


    Qt Code:
    1. void SignalPlotFrame::moveUp(int row)
    2. {
    3. if (row > 0)
    4. {
    5. QwtPlot *plotOne = static_cast<QwtPlot*>(
    6. table->cellWidget (row - 1, 0));
    7. QwtPlot *plotTwo = static_cast<QwtPlot*>(
    8. table->cellWidget (row, 0));
    9. table->setCellWidget (row - 1, 0, plotTwo);
    10. table->setCellWidget (row, 0, plotOne);
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    Testing the same code with Qt 4.2.1, it does not work any more, and looking at the implementation of QTableWidget::setCellWidget and QAbstractItemView::setIndexWidget I saw that it changed from 4.1.0 and that now it first tests whether there was a widget in the cell before setting the new one, and if so it deletes it.

    Is it possible with QTableWidget to remove/overright the old widget from a cell without deleting it? Or should I better invest some effort in implementing my own model/view/delegate classes for handling such situations?

  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: QTableWidget swapping rows with widgets in cells

    I think Qwt gives you a way to plot directly on a painter so implementing a delegate doing so should be easy.

Similar Threads

  1. QTableWidget (resizing rows, turning off selection, etc.)
    By kiss-o-matic in forum Qt Programming
    Replies: 6
    Last Post: 11th January 2007, 02:57
  2. 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.