Results 1 to 12 of 12

Thread: QListWidget Question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Thanks
    6
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QListWidget Question

    In almost all of my apps I put a function setButtons() where I enable/disable all kinds of controls.
    After every action, like inserting records, opening files, closing files, editing fields or making coffee etc, I call setButtons() to put every control in a valid state. Once used to this approach, you'll never have to think about how to keep things in sync again.

  2. #2
    Join Date
    Jan 2010
    Posts
    19
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget Question

    For highlighting a row use setCurrentItem() or an equivalent for selection.
    I'm not sure what I'm doing wrong, but even when I set the current item, it does not get highlighted.

    For example:
    Qt Code:
    1. ui.layerList->setCurrentItem(layer7);
    To copy to clipboard, switch view to plain text mode 
    After doing this, the current item is set to layer7, but it isn't highlighted.
    I also tried QListWidgetItem::setSelected(true) but it still doesnt get highlighted.

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

    Default Re: QListWidget Question

    We'd have to see the bigger picture. We don't even know what "layer7" is What is the selection mode of the widget? Is the item selectable at all, what does flags() return for it?
    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.


  4. #4
    Join Date
    Jan 2010
    Posts
    19
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget Question

    Here's a snippet of my code (the last 3 lines cane be ignored):

    Qt Code:
    1. void warmup::on_addLayerButton_clicked()
    2. {
    3. int nRows = ui.layerList->count();
    4.  
    5. Qt::ItemFlags flags = Qt::ItemIsDragEnabled | Qt::ItemIsSelectable | Qt::ItemIsEnabled;
    6. newLayer->setText(tr("Layer %1").arg(nRows+1));
    7. ui.layerList->addItem(newLayer);
    8. newLayer->setFlags(flags);
    9.  
    10. clearLayerData();
    11. ui.layerList->setCurrentItem(newLayer);
    12. getLayerData(ui.layerList->row(newLayer));
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 

    I have a QListWidget 'layerList', and when the 'Add' button is clicked, a new QListWidgetItem 'newLayer' is created. I'm trying to figure out how to make it so that when a 'newLayer' is created, is it automatically set as the current item AND highlighted. So far all I have managed to do is set it as the current item. The flags for the 'newLayer' are listed in the code above, the selection mode for 'layerList' is set to SingleSelection, and the selection behavior for 'layerList' is SelectItems. I hope this helps clear up what I'm asking

  5. #5
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: QListWidget Question

    Try setCurrentItem(newLayer, QItemSelectionModel::Select)
    It's nice to be important but it's more important to be nice.

  6. #6
    Join Date
    Jan 2010
    Posts
    19
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget Question

    Quote Originally Posted by axeljaeger View Post
    Try setCurrentItem(newLayer, QItemSelectionModel::Select)
    Hmm, still doesn't seem to be working

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

    Default Re: QListWidget Question

    To me it seems you are doing something wrong if setSelected(true) didn't work. Either the item is not selectable or your code is never ran or something unselects the item after you select it.
    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. New member and a question about QListWidget
    By Pokepasa in forum Qt Programming
    Replies: 2
    Last Post: 4th November 2009, 10:24
  2. QListWidget question
    By rishid in forum Qt Programming
    Replies: 8
    Last Post: 18th January 2008, 13:50
  3. extracting a item from a QListWidget question
    By impeteperry in forum Qt Programming
    Replies: 1
    Last Post: 27th January 2007, 09:08
  4. question regarding qlistwidget
    By amulya in forum Qt Programming
    Replies: 1
    Last Post: 6th October 2006, 07:17
  5. Replies: 1
    Last Post: 7th April 2006, 11:13

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.