Results 1 to 2 of 2

Thread: Unable to remove Focus from QTableWidget even with setFocusPolicy(Qt::NoF

  1. #1
    Join Date
    Oct 2009
    Posts
    66
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Unable to remove Focus from QTableWidget even with setFocusPolicy(Qt::NoF

    Hi,
    I am new to Qt Environment, i am using a QTablewidget, where i have some some rows and some columns, when the tableWidget was created from QTableWidget, the focus property was set as

    Qt Code:
    1. tableWidget->setFocusPolicy(Qt::NoFocus );
    To copy to clipboard, switch view to plain text mode 

    But still when a cell is clicked on the table, the cell is getting highlighted . Can anyone share as to what can be the reason for the focus not getting cleared from the tableWidget.

    Adding the code


    Qt Code:
    1. {
    2. tableWidget = new QTableWidget(4, 4,RenderScheduleLayout );
    3. QRect rect(40,100,650,200);
    4. tableWidget->setGeometry(rect);
    5. for (int i =0; i < 4; i++)
    6. tableWidget->setColumnWidth(i,50);
    7. for (int i =0; i < 4; i++)
    8. tableWidget->setRowHeight(i,20);
    9.  
    10. tableWidget->setFocusPolicy(Qt::NoFocus)
    11.  
    12. connect(tableWidget,SIGNAL(cellClicked(int,int)),this,SLOT(doSomething(int,int)));
    13. }
    14.  
    15. void Widget::doSomething(int row, int column){
    16.  
    17. QTableWidgetItem *newItem = new QTableWidgetItem(tr(""));
    18. newItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
    19. tableWidget->setItem(row, column, newItem);
    20. tableWidget->clearFocus();
    21. }
    To copy to clipboard, switch view to plain text mode 
    I am also doing a clear focus on this but still the focus on the selected cell is shown, i dont know how to remove the focus as its not being removed using tableWidget->setFocusPolicy(Qt::NoFocus)

    Please help me on this issue.
    Last edited by wysota; 23rd October 2009 at 01:34. Reason: missing [code] tags

  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: Unable to remove Focus from QTableWidget even with setFocusPolicy(Qt::NoF

    What happens if you do:
    Qt Code:
    1. tableWidget->viewport()->setFocusPolicy(Qt::NoFocus);
    To copy to clipboard, switch view to plain text mode 

    I'm sure you can get rid of focus by not returning ItemIsEnabled flag for an item but I'm not sure that's what you want.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Removing Focus from QTableWidget
    By kapoorsudhish in forum Newbie
    Replies: 2
    Last Post: 22nd October 2009, 15:16
  2. QTableWidget Bug : can't remove row !
    By QAmazigh in forum Qt Programming
    Replies: 7
    Last Post: 17th May 2009, 12:14
  3. How to Compile VTKDesigner2 with Qt?
    By alfredoaal in forum Newbie
    Replies: 0
    Last Post: 5th September 2008, 06:34
  4. Focus of cells in a QTableWidget
    By SailinShoes in forum Qt Programming
    Replies: 4
    Last Post: 9th June 2008, 09:19
  5. Replies: 3
    Last Post: 8th September 2006, 19:54

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.