Results 1 to 5 of 5

Thread: QListWidget and selecting an item

  1. #1
    Join Date
    Feb 2007
    Posts
    61
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QListWidget and selecting an item

    Hi

    I am new to QT4 and are currently testing how to use the different widgets. I am used to win32 programming and therefore the QListWidget is getting on my nerves. The problem is that when using the windowsxpstyle I only select the item instead of the row when clicking an item. This is not the windowsxp way even though it is using the windowsxp style. I remember from win32 programming that listboxes usually allowed selecting a row and not only the item.

    I changed the style to plastique and cleanlooks and then it worked as expected. I tried setting the SelectionBehavior to QAbstractItemView::SelectRows and that did not work.

    What I want is to get a look that is as similar to regular win32 apps as possible.

    The code:
    Qt Code:
    1. #include <QApplication>
    2. #include <QListWidget>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7.  
    8.  
    9. //list.setSelectionBehavior(QAbstractItemView::SelectRows);
    10.  
    11. list.addItem("Hello!");
    12. list.addItem("World!");
    13.  
    14. list.resize(200, 400);
    15. list.show();
    16.  
    17. return app.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 

    Any ideas on how to get the list to behave as intended on windows?

  2. #2
    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: QListWidget and selecting an item

    Quote Originally Posted by invictus View Post
    I am used to win32 programming and therefore the QListWidget is getting on my nerves. The problem is that when using the windowsxpstyle I only select the item instead of the row when clicking an item. This is not the windowsxp way even though it is using the windowsxp style. I remember from win32 programming that listboxes usually allowed selecting a row and not only the item.
    As a side note, at least Windows Explorer works this way in "list view mode".

    Any ideas on how to get the list to behave as intended on windows?
    Maybe you could use a tree widget instead? A bit more code but should do about what you want
    Qt Code:
    1. #include <QApplication>
    2. #include <QTreeWidget>
    3. #include <QHeaderView>
    4.  
    5. int main(int argc, char* argv[])
    6. {
    7. QApplication a(argc, argv);
    8.  
    9. tree.header()->hide();
    10. tree.setColumnCount(1);
    11. tree.setRootIsDecorated(false);
    12.  
    13. tree.addTopLevelItem(new QTreeWidgetItem(QStringList("Hello!")));
    14. tree.addTopLevelItem(new QTreeWidgetItem(QStringList("World!")));
    15.  
    16. tree.resize(200, 400);
    17. tree.show();
    18.  
    19. return a.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Feb 2007
    Posts
    61
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget and selecting an item

    Quote Originally Posted by jpn View Post
    As a side note, at least Windows Explorer works this way in "list view mode".
    I was thinking more in the line of regular application lists in the common controls. Its kind of strange that I have to use Tree's in order to give the correct list behavior when QT obviously have 2 different listwidgets (listview, listwidgets).

  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: QListWidget and selecting an item

    Quote Originally Posted by invictus View Post
    Its kind of strange that I have to use Tree's in order to give the correct list behavior when QT obviously have 2 different listwidgets (listview, listwidgets).
    I know, the usage of a tree was an ugly workaround. Anyway, they're not "different" lists. QListWidget is a QListView. QListWidget just includes a built-in model and convenience methods. I suggest you send a suggestion at Task-Tracker.
    J-P Nurmi

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

    Default Re: QListWidget and selecting an item

    Quote Originally Posted by jpn View Post
    I suggest you send a suggestion at Task-Tracker.
    I did and got the following as reply:

    Thank you for your input on this issue. Unfortunately this is the
    intended behavior when using the Windows style, the same behavior is
    presend on Explorer too.
    You can either use a QTreeWidget/QTreeView or a different style (e.g.
    Plastique ) to achieve the desired behavior.
    To be honest I am not impressed...to be forced to use either a tree or a different style in order to achieve a consistant behavior...I am beyond words. Perhaps I have missed something important about how QT is designed (however, I generally love the QT API) and therefore cant see why this should be intended behavior and why its a good idea to refuse the coder to be allowed to force the desired behavior.

Similar Threads

  1. Replies: 1
    Last Post: 19th April 2007, 23:23

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.