Results 1 to 3 of 3

Thread: QCombobox - disable an item but still retain it in the list

  1. #1
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    39
    Thanks
    15
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QCombobox - disable an item but still retain it in the list

    is it possible to disable a single item (or more if I so choose) in a QCombobox.

    I do not want to remove an item from the list just gray it out or so it cant be selected.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCombobox - disable an item but still retain it in the list

    May be you can try -
    Setting your own view ( QListWidget ) to the combobox and then disabling the items you want with setItemFlags.

    Other way would be by accessing the item through combobox's model and setting the enabled flag. Am looking for a way to do this.. will post if I find.
    Till then you can try the above method


    Added after 14 minutes:


    Well, found something,-
    Qt Code:
    1. void QStandardItem::setFlags(Qt::ItemFlags flags)
    2. {
    3. setData((int)flags, Qt::UserRole - 1);
    4. }
    To copy to clipboard, switch view to plain text mode 

    So you can try the following -
    QComboBox::setItemData(row,false, Qt::UserRole - 1);

    I guess it should work...
    Last edited by aamer4yu; 19th March 2012 at 13:41.

  3. #3
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: QCombobox - disable an item but still retain it in the list

    you can edit the color(i.e. for convinience gray tones) of your item you disabled and doing nothing upon it's selection.

Similar Threads

  1. Show QComboBox list while editing
    By radix07 in forum Qt Programming
    Replies: 0
    Last Post: 14th October 2011, 16:52
  2. Replies: 0
    Last Post: 10th March 2011, 11:44
  3. Disable QTreeView item
    By tmmak in forum Qt Programming
    Replies: 2
    Last Post: 1st February 2011, 08:33
  4. QComboBox item disable?
    By Equilibrium in forum Qt Programming
    Replies: 8
    Last Post: 28th November 2007, 17:41
  5. [QT3] QComboBox: Disable adding items on Enter-keypress
    By BrainB0ne in forum Qt Programming
    Replies: 7
    Last Post: 14th January 2006, 19:43

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.