Results 1 to 5 of 5

Thread: Problem in Cut Operation

  1. #1
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem in Cut Operation

    Hi,
    i made a dll that provides a table in the main project and some basic operations that can be done on table. Compare it with the table of excel, it provides the functions of cut,copy,paste etc on context menu.

    The requirement was to make the grid ( table) behaviour more similar to excel. For this the selection of the cells in the table also need to be changed. So i also used delegates here.

    i am having problem in cut operations.
    First this is the delegate to use for table border thickening.

    Qt Code:
    1. GridDelegate::GridDelegate(QObject *parent) : QItemDelegate(parent)
    2. {
    3.  
    4. }
    5.  
    6. void GridDelegate::drawFocus(QPainter* painter,
    7. const QStyleOptionViewItem &option,
    8. const QRect &rect) const
    9.  
    10. {
    11. if (option.state & QStyle::State_HasFocus)
    12.  
    13. {
    14.  
    15. QPen pen(Qt::black);
    16.  
    17. pen.setWidth(3);
    18.  
    19. painter->setPen(pen);
    20.  
    21. painter->drawRect(rect);
    22.  
    23. }
    24. else if (option.state & QStyle::State_Selected)
    25. {
    26. QPen pen(Qt::black);
    27.  
    28. pen.setWidth(3);
    29.  
    30. painter->setPen(pen);
    31.  
    32. painter->drawRect(rect);
    33. }
    34. }
    To copy to clipboard, switch view to plain text mode 

    in the table i use as:

    Qt Code:
    1. void Eventtable::tableItemDblClicked(QTableWidgetItem *item)
    2. {
    3. QTableWidget *tt = item->tableWidget();
    4.  
    5. int nRow = tt->row(item);
    6. int nColumn = tt->column(item);
    7.  
    8. switch (nColumn)
    9. {
    10.  
    11. case 1:
    12. eventtable_data->setItemDelegate(new SpinBoxDelegate(this));
    13. break;
    14. .........................
    15. default:
    16. if(tt == eventtable_data)
    17. tt->setItemDelegate(new GridDelegate(this));
    18. else
    19. if(tt == eventtable_msg)
    20. if(nColumn >= 1)
    21. {
    22. tt->setItemDelegate(new EditDelegate(this));
    23. }
    24. else
    25. tt->setItemDelegate(new GridDelegate(this));
    26. break;
    27. }
    28. }
    To copy to clipboard, switch view to plain text mode 
    this way i am able to get the delegates on dblclik of the cell.

    Now if i cut the item in cell, and again select cell the border was not showing around the cell, even though it was selected.

    to get around the problem i set the text in the cell as " " instead of "" in the cut function.
    cut looks like this :
    Qt Code:
    1. void QGrid::cut()
    2. {
    3. QString str,str1;
    4. foreach (QTableWidgetItem *i,this->selectedItems())
    5. {
    6. QString strPrint(i->text());
    7. strPrint+="\t";
    8. str+=strPrint;
    9. clip->setText(str,QClipboard::Clipboard);
    10. i->setText(" ");
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    But then again, in the first column i did a validation as per which space must not be in the first column. the very concept for cut function and showing the cell selected failed here.
    if i remove space in cut, the selection border is not showing. if i keep space error due to space validation comes.

    so how can i show the border across the cell ?
    how can i activate the delegate on keyboard keys. for instance if my cell is selected, pressing any key (alphanumeric) must trigger the edit mode and thus the corresponding delegate for the cell. same must be the operation of F2 key.

    Please help if someone has a workaround. if i am not clear in my explanation tell me.

    Thanx in advance
    Do what u r afraid to do, and the death of fear is sure.

  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: Problem in Cut Operation

    I think you should use a model-view approach here.

    Quote Originally Posted by ankurjain
    this way i am able to get the delegates on dblclik of the cell.
    This is not good. The delegate should be set upon creation of the view and not on double click. The double click should trigger edit mode, which in turn should ask the delegate to provide an editor for the cell. You shouldn't mess with the delegates this way.

    so how can i show the border across the cell ?
    In what way should it be "across"? You mean you want to have a rectangle containing many cells selected? If you use the model-view approach this should be done automatically.

    how can i activate the delegate on keyboard keys. for instance if my cell is selected, pressing any key (alphanumeric) must trigger the edit mode and thus the corresponding delegate for the cell. same must be the operation of F2 key.
    You don't "activate" the delegate. The view asks the delegate to do some things... You should only trigger appropriate actions on the view (like update() and edit()).

    In your case I think you need to set edit triggers (QAbstractItemView::setEditTriggers()) to QAbstractItemView:oubleClicked|QAbstractItemView::EditKeyPressed.

  3. #3
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem in Cut Operation

    hi wysota,
    thanks for ur reply ...

    but since i was put in a team in which design and work was already going on. and this table was constructed using QTableWidget instead of using Model/View Architecture.

    Qt Code:
    1. In what way should it be "across"?
    To copy to clipboard, switch view to plain text mode 

    I actually want the border around the cell ( sry for bad english ) or if a row is selected the border ( rectangle ) around the row.

    Qt Code:
    1. This is not good. The delegate should be set upon creation of the view and not on double click. The double click should trigger edit mode, which in turn should ask the delegate to provide an editor for the cell. You shouldn't mess with the delegates this way.
    To copy to clipboard, switch view to plain text mode 

    i am calling the editor in the delegate. as one requirement was like that, bigger editor window on dbl clking the cell.

    Just For My Knowledge
    Can i edit data also and update it in Model/View architecuture ??

    Also deadline is close for 1st release, so i can't change the design right now.
    So please help out ....
    Last edited by ankurjain; 14th April 2006 at 05:42.
    Do what u r afraid to do, and the death of fear is sure.

  4. #4
    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: Problem in Cut Operation

    Quote Originally Posted by ankurjain
    but since i was put in a team in which design and work was already going on. and this table was constructed using QTableWidget instead of using Model/View Architecture.
    It doesn't mean the team can't change its decisions, right? You'll experience lots of problems with the itembased approach. The model-view architecture handles some aspects of the application on its own. Without it, you'll have much more coding to do.

    I actually want the border around the cell ( sry for bad english ) or if a row is selected the border ( rectangle ) around the row.
    And the problem is...? Drawing the selection is the views and delegates responsibility. You have a selection model associated with the view and you can act depending on its contents.

    i am calling the editor in the delegate. as one requirement was like that, bigger editor window on dbl clking the cell.
    I don't quite understand... You want to have two different kinds of editors? That surely doesn't require changing the delegate upon a click on the cell.

    Can i edit data also and update it in Model/View architecuture ??
    Of course you can.

    Also deadline is close for 1st release, so i can't change the design right now.
    It's not that much more work as you think. And you'll probably save some time later. It's better to correct misdesigns earlier, because the consequences of such misdesigned won't require as many changes to the application as when you want to correct them on a later stage.

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

    ankurjain (14th April 2006)

  6. #5
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem in Cut Operation

    ok,

    right now i m working towards alpha release ( 1 day more to go, hiw can i cahnge the design rite now) , after this release i will try to change the design again and communicate to team and integrate with their code.

    if some problem there i will again post here.

    Thanx 4 guidance.
    Do what u r afraid to do, and the death of fear is sure.

Similar Threads

  1. Replies: 8
    Last Post: 27th March 2013, 11:51
  2. discontinuous QTimeLine problem
    By yagabey in forum Qt Programming
    Replies: 0
    Last Post: 2nd December 2008, 21:20
  3. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  4. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  5. change of ownershiip operation not permaitted while build
    By quickNitin in forum Installation and Deployment
    Replies: 5
    Last Post: 16th May 2006, 12:13

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.