Results 1 to 3 of 3

Thread: [Qt-3] QTable question

  1. #1
    Join Date
    Feb 2006
    Posts
    22
    Thanks
    4
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default [Qt-3] QTable question

    Hello!
    I need to find some special way to provide cell editors for table.
    Instantiating editor each time QTable::createEditor() is called is not
    suitable because it takes sufficient amount of time.
    I've looked through examples and there is a solution (ex. bigtable) to
    avoid multiple editor instantiation for each cell.
    I want avoid multiple instantiation for each column! I mean all cells
    in the same column should use one instance of editor.

    I've played around overriding theese methods but didn't find
    particular solution. Either widgets don't disappear when i finish
    editing either they start blinking in all cells of a column.

    QIntDict<QWidget> widgets;

    QWidget * QtsDataTable::createEditor ( int row, int col, bool
    initFromCell ) const
    {
    QWidget * w = widgets.find(col);
    if( w == 0)
    {
    /*here goes widget instantiation and inserting it into widgets dict*/
    }
    return w;
    }

    void QtsDataTable::insertWidget( int r, int c, QWidget *w )
    {
    }

    QWidget * QtsDataTable::cellWidget( int r, int c ) const
    {
    return 0;
    }

    void QtsDataTable::clearCellWidget( int r, int c )
    {
    }

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

    Default Re: [Qt-3] QTable question

    I think you need to reimplement endEdit() too,

  3. The following user says thank you to wysota for this useful post:

    a550ee (28th September 2006)

  4. #3
    Join Date
    Feb 2006
    Posts
    22
    Thanks
    4
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: [Qt-3] QTable question

    Hello!
    Thanks to you I make it work. In fact, I get rid of all overrides (createCellWidget, insertWidget, etc. ) except for beginEdit() and endEdit(). I don't know how good this solution is, but, as I mentioned before, it works.
    To ensure I didn't forget anything, I'll provide code for beginEnd() and endEdit() here.

    Qt Code:
    1. QWidget * QtsDataTable::beginEdit ( int row, int col, bool replace )
    2. {
    3. ensureCellVisible( row, col );
    4. QWidget * w = 0;
    5. /*here goes instantiating, setting values, etc.*/
    6. if(w != 0)
    7. {
    8. w->installEventFilter ( this );
    9. QRect cr = cellGeometry( row, col );
    10. w->resize( cr.size() );
    11. moveChild( w, cr.x(), cr.y() );
    12. w->setActiveWindow();
    13. w->show();
    14. w->setFocus();
    15. }
    16. updateCell( row , col );
    17. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void QtsDataTable::endEdit ( int row, int col, bool accept, bool replace )
    2. {
    3. QWidget * w = 0;
    4. /*here goes setting values, etc.*/
    5. if(w != 0)
    6. {
    7. w->hide();
    8. w->removeEventFilter( this );
    9. }
    10. setEditMode( QTable::NotEditing, -1, -1);
    11. viewport()->setFocus();
    12. updateCell( row, col);
    13. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. copy-paste the content of a QTable
    By greencastor in forum Qt Programming
    Replies: 2
    Last Post: 13th September 2006, 12:20
  2. QThread exit()/quit() question
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 28th August 2006, 14:38
  3. QTable column stretchable with minimum Width
    By sunil.thaha in forum Qt Programming
    Replies: 0
    Last Post: 24th April 2006, 13:17
  4. Problem with QTable
    By zlatko in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 10:00
  5. QTable..Vs.. QListView
    By :db:sStrong in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2006, 21:03

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.