Results 1 to 5 of 5

Thread: QComboBoxes in QTableWidget : which is focused ?

  1. #1
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default QComboBoxes in QTableWidget : which is focused ?

    Hello

    I have a QTableWidget that is composed of 4 columns and several rows.
    2 columns are filled with QTableWidgetItems, it's just text.
    2 columns are filled with QComboBoxes.

    So, when I want to add a row in my table, I use the setItem function in order to add the 2 QTableWidgetItems. That's ok.
    After that I need to add the 2 QComboBoxes, and I do it with the setCellWidget function. That's ok too.

    My problem is that I need to know which cell has the focus when the user clicks on a button. So I've connected the signal clicked() (from the button) to a slot. The slot loops over the table and look at each row/colum in order to know if the cell has the focus.

    For a given cell, I can know if it has the focus doing this :
    - if its colum number = 0 or 1 : the cell is a QTableWidgetItem and I can test with :
    Qt Code:
    1. if ((table->item(row, column))->isSelected() == true)
    To copy to clipboard, switch view to plain text mode 
    - if its colum number = 2 or 3 : the cell is a QComboBox and I can test with :
    Qt Code:
    1. if ((table->cellWidget(row, column))->hasFocus() == true)
    To copy to clipboard, switch view to plain text mode 

    The matter is that the second test is never TRUE.
    I've no compilation errors.
    If I replace the QComboBoxes by QListWidgets, the test is OK.

    I don't understand what's the problem ^_^.
    Could you help me, please ?



    EDIT : I think that the QComboBoxes lost focus when the user clic the button
    I'm under Win2000. I'll try to use signal/slots to detect the last cell that had the focus.

    I don't find any QTableWidget signal that is emitted when I clic a cell that contains a QComboBox . I don't know what to do :-/
    I could use currentRow() and currentColumn to know the current object positon, but currentColumn doesn't care about the QComboBoxes in my cells... Unlike currentRow() .



    .
    Last edited by Nyphel; 11th April 2007 at 16:14.

  2. #2
    Join Date
    Feb 2007
    Posts
    73
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBoxes in QTableWidget : which is focused ?

    Quote Originally Posted by Nyphel View Post
    EDIT : I think that the QComboBoxes lost focus when the user clic the button
    I'm under Win2000. I'll try to use signal/slots to detect the last cell that had the focus.

    I don't find any QTableWidget signal that is emitted when I clic a cell that contains a QComboBox . I don't know what to do :-/
    I could use currentRow() and currentColumn to know the current object positon, but currentColumn doesn't care about the QComboBoxes in my cells... Unlike currentRow() .
    You can connect to one of the slots for QComboBox (like activated), or you could use a QComboBox derivation and re-implement the focusInEvent handler, perhaps emitting your own signal.

    The alternative is to develop your own delegate and process focus in events in the event filter.

    HTH,
    Susan

  3. #3
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QComboBoxes in QTableWidget : which is focused ?

    Hi,

    I can't really use the QComboBox signals/slots, because the user can add rows to my table... And this operation adds QComboBoxes in the cells. Like I don't store them in memory, using vectors for example, I can't say that the signal is connected to each QComboBox.

    This is the reason why I would like to detect a focus change : I could go thrut the table and look at each cell in order to know the one that is focused.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QComboBoxes in QTableWidget : which is focused ?

    What kind of data does the combo box contain? I'd suggest using a custom delegate or an item editor factory to provide the combo box as a custom editor instead of using cell widgets.
    J-P Nurmi

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

    Nyphel (13th April 2007)

  6. #5
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QComboBoxes in QTableWidget : which is focused ?

    I only store text in the QComboBoxes

    That seems very interesting JPN, and there are examples too
    Thanks a lot, I will give a big look !

Similar Threads

  1. QTableWidget (resizing rows, turning off selection, etc.)
    By kiss-o-matic in forum Qt Programming
    Replies: 6
    Last Post: 11th January 2007, 02:57
  2. QTableWidget issues
    By Djony in forum Qt Programming
    Replies: 42
    Last Post: 20th December 2006, 00:27
  3. print QTableWidget
    By chak_med in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2006, 19:46
  4. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 19:46
  5. Replies: 6
    Last Post: 5th March 2006, 22:05

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.