Results 1 to 9 of 9

Thread: Set Foucus Out Of QtableView

  1. #1
    Join Date
    Dec 2010
    Location
    South Africa
    Posts
    56
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Set Foucus Out Of QtableView

    Good Day All.

    I have an interesting problem that i hope is simple.

    I have a table that when a certain cell is blank it triggers the following function:

    Qt Code:
    1. void myfrm::cellIsEmpty()
    2. {
    3. //Run if the item cell is empty
    4. qDebug()<< "Im A Empty Cell";
    5. ui->tableview->viewport()->setFocusPolicy(Qt::NoFocus); //tried with and without does not work
    6. ui->in_total->setFocus();
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 

    Results: When the function runs i do see the qdebug "Im A Empty Cell" So i know the functions is being called however the focus of the application remains on the next field of the tableview.

    Expected Result:
    I expect the focus to be on the lineedit "in_total" For editing


    Any Help Would be appreciated.


    Regards

  2. #2
    Join Date
    Dec 2010
    Location
    South Africa
    Posts
    56
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Set Foucus Out Of QtableView

    Good day. Im bumping this as i still do not know how to do it.

    Could someone please help

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Set Foucus Out Of QtableView

    How and when is the function being called?

  4. #4
    Join Date
    Dec 2010
    Location
    South Africa
    Posts
    56
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Set Foucus Out Of QtableView

    Qt Code:
    1. void form1::mycellChanged(int myrow, int mycol)
    2. {
    3. QTableWidgetItem *celldata = ui->table_items->item(myrow,0);
    4. QString mycode = celldata->text();
    5. if(mycode!="")
    6. {
    7. //othercodehere
    8. }
    9. else{
    10. cellIsEmpty();
    11. }
    12. }
    13.  
    14. void form1::cellIsEmpty()
    15. {
    16. //Run if the item cell is empty
    17. qDebug()<< "Im A Empty Cell";
    18. ui->table_items->viewport()->setFocusPolicy(Qt::NoFocus);
    19. //viewport()->setFocusPolicy(Qt::NoFocus);
    20. ui->in_total->setFocus();
    21.  
    22. }
    To copy to clipboard, switch view to plain text mode 


    Is there anyhting else you need as you can see in my commented code i have tried a couple of things but i cant get it to work

    Regards

  5. #5
    Join Date
    Dec 2010
    Location
    South Africa
    Posts
    56
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Set Foucus Out Of QtableView

    BUMP. Months with no help. Can Anyone please have a look at it

  6. #6
    Join Date
    Nov 2006
    Location
    indonesia
    Posts
    55
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Set Foucus Out Of QtableView

    Hi,
    Are you have create signal and slot for your QTableWidget in your code ?
    you can add this code in your code :
    Qt Code:
    1. //Create Signal and slot for QTableWidget
    2. connect(ui->tableWidget, SIGNAL(cellChanged ( int, int)), this, SLOT(mycellChanged(int, int)));
    To copy to clipboard, switch view to plain text mode 

    and implement mycellChanged slot like this :
    Qt Code:
    1. //show debug information when QTableWidgetItem Changed
    2. void basicQTableWidget::mycellChanged(int myrow, int mycol)
    3. {
    4. QTableWidgetItem *celldata = ui->tableWidget->item(myrow, mycol);
    5. if(celldata->text()!="")
    6. {
    7. qDebug()<<"Table Position [" + QString::number(myrow) +
    8. ", " + QString::number(mycol) + "] = " + celldata->text();
    9. }
    10. else
    11. {
    12. qDebug()<<"Table Position [" + QString::number(myrow) + ", " +
    13. QString::number(mycol) + "] is Empty";
    14. }
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 

    you can get the complete source code in here : http://toto-share.com/2011/11/qt-qtablewidget-tutorial

    Are this website address solve your problem ?

    Best regards,

    Toto

  7. #7
    Join Date
    Dec 2010
    Location
    South Africa
    Posts
    56
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Set Foucus Out Of QtableView

    Quote Originally Posted by myta212 View Post
    Hi,
    Are you have create signal and slot for your QTableWidget in your code ?
    you can add this code in your code :

    ...


    Are this website address solve your problem ?

    Best regards,

    Toto
    This does not help at all.
    I don't think you even read the posts
    If you did you can see that i do everything you suggest.
    . I can use a table i just need to move the focus out of the table once we have finished doing my tests.

  8. #8
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Set Foucus Out Of QtableView

    Just a guess.. maybe changing the focus in an event that occurs when the focus is just changes gives you a problem ?

    You might try to start a single shot timer instead of doing ui->in_total->setFocus();
    Then in you timer event code, do ui->in_total->setFocus();

    Regards,
    Marc

  9. #9
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Set Foucus Out Of QtableView

    Another guess - You're not confusing focus with the highlight of the selected cell, are you? If you type something in does it show up in the lineEdit? If that's the case put the following in your slot:
    Qt Code:
    1. ui->table_items->clearSelection();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QTableView and QLineEdit OUTSIDE of QTableView, like Excel
    By JoZCaVaLLo in forum Qt Programming
    Replies: 10
    Last Post: 13th May 2011, 13:20
  2. Replies: 2
    Last Post: 26th November 2009, 04:45
  3. Help QTableView
    By vinny gracindo in forum Newbie
    Replies: 1
    Last Post: 22nd November 2009, 00:44
  4. QTableView
    By dragon in forum Qt Programming
    Replies: 0
    Last Post: 22nd September 2008, 16:53
  5. QTableView
    By fpujol in forum Qt Programming
    Replies: 4
    Last Post: 16th January 2007, 08:17

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
  •  
Qt is a trademark of The Qt Company.