Results 1 to 11 of 11

Thread: setEditorData() for QComboBox Delegate

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setEditorData() for QComboBox Delegate

    The combobox has to show whatever data is in the model for the current cell and not what you want. You can say that if the model doesn't return data for an index, "a" should be set as the combobox current item. But then the model will never contain "a" (or its equivalent) unless you first change the combobox to something else, close the editor, reopen it again and change the cell back to "a".
    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.


  2. #2
    Join Date
    Feb 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: setEditorData() for QComboBox Delegate

    I have been working on the same thing. Like wysota said, the combobox has to show whatever data is in the model for the current cell. to initialise the combobox to 'a', set the value in the model to 'a'. Then in the setEditorData() function you can retrieve the value in the model using something like this.

    Qt Code:
    1. QString value = index.model()->data(index, Qt::DisplayRole).toString();
    To copy to clipboard, switch view to plain text mode 

    Then you can set the current index like you have previously.

    Qt Code:
    1. QComboBox *comboBox = static_cast<QComboBox*>(editor);
    2. comboBox->setCurrentIndex(comboBox->findText(value));
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 2
    Last Post: 29th December 2012, 14:14
  2. Need help with my delegate
    By Guilo in forum Qt Programming
    Replies: 6
    Last Post: 1st July 2010, 12:15
  3. QCombobox as QTableView delegate
    By martonmiklos in forum Qt Programming
    Replies: 7
    Last Post: 13th June 2010, 15:23
  4. Again QTableWidget and QComboBox delegate
    By Aki-Matti in forum Qt Programming
    Replies: 2
    Last Post: 4th March 2008, 13:40
  5. Delegate but when
    By uygar in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2007, 20:28

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.