Results 1 to 3 of 3

Thread: Removing Focus from QTableWidget

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

    Default Removing Focus from QTableWidget

    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

    tableWidget->setFocusPolicy(Qt::NoFocus );

    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


    {
    tableWidget = new QTableWidget(4, 4,RenderScheduleLayout );
    QRect rect(40,100,650,200);
    tableWidget->setGeometry(rect);
    for (int i =0; i < 4; i++)
    tableWidget->setColumnWidth(i,50);
    for (int i =0; i < 4; i++)
    tableWidget->setRowHeight(i,20);

    tableWidget->setFocusPolicy(Qt::NoFocus)

    connect(tableWidget,SIGNAL(cellClicked(int,int)),t his,SLOT(doSomething(int,int)));
    }

    void Widget::doSomething(int row, int column){

    QTableWidgetItem *newItem = new QTableWidgetItem(tr(""));
    newItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
    tableWidget->setItem(row, column, newItem);
    tableWidget->clearFocus();
    }

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Removing Focus from QTableWidget

    Focus and selection are two different things. Use
    Qt Code:
    1. newItem->setFlags( /*Qt::ItemIsSelectable |*/ Qt::ItemIsEnabled );
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Removing Focus from QTableWidget

    Thanks Lykurg, it worked. It will also be good if you can help me on thread

    http://www.qtcentre.org/forum/f-newb...iew-24993.html

    Thanks.

Similar Threads

  1. removing focus of application?
    By triperzonak in forum Qt Programming
    Replies: 0
    Last Post: 16th July 2008, 15:17
  2. Focus of cells in a QTableWidget
    By SailinShoes in forum Qt Programming
    Replies: 4
    Last Post: 9th June 2008, 08:19
  3. Removing a QWidget object from a QTableWidget cell
    By mclark in forum Qt Programming
    Replies: 5
    Last Post: 13th March 2008, 15:19
  4. QTable, Removing cell focus
    By Kubil in forum Qt Programming
    Replies: 2
    Last Post: 27th July 2007, 10:13
  5. Replies: 3
    Last Post: 8th September 2006, 18: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.