PDA

View Full Version : QListWidget and selecting an item



invictus
8th June 2007, 00:05
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:

#include <QApplication>
#include <QListWidget>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QListWidget list;

//list.setSelectionBehavior(QAbstractItemView::Selec tRows);

list.addItem("Hello!");
list.addItem("World!");

list.resize(200, 400);
list.show();

return app.exec();
}

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

jpn
8th June 2007, 08:08
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 :)


#include <QApplication>
#include <QTreeWidget>
#include <QHeaderView>

int main(int argc, char* argv[])
{
QApplication a(argc, argv);

QTreeWidget tree;
tree.header()->hide();
tree.setColumnCount(1);
tree.setRootIsDecorated(false);

tree.addTopLevelItem(new QTreeWidgetItem(QStringList("Hello!")));
tree.addTopLevelItem(new QTreeWidgetItem(QStringList("World!")));

tree.resize(200, 400);
tree.show();

return a.exec();
}

invictus
8th June 2007, 09:08
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).

jpn
8th June 2007, 09:11
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 (http://trolltech.com/developer/task-tracker).

invictus
19th June 2007, 11:59
I suggest you send a suggestion at Task-Tracker (http://trolltech.com/developer/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.