QListWidget . First attempts
-
I start using QListWidget. The snippet the follow, shows no item inside the QListWidget. What's wrong?
@
QListWidget* list= new QListWidget;
list->addItem(new QListWidgetItem("Banana"));
list->addItem(new QListWidgetItem("Apple"));
list->addItem(new QListWidgetItem("Orange"));
list->addItem(new QListWidgetItem("Grapes"));
list->addItem(new QListWidgetItem("Jayesh"));
list->show();
@ -
the snipet I post in the first post:
@ QListWidget* list= new QListWidget;
list->addItem(new QListWidgetItem("Banana"));
list->addItem(new QListWidgetItem("Apple"));
list->addItem(new QListWidgetItem("Orange"));
list->addItem(new QListWidgetItem("Grapes"));
list->addItem(new QListWidgetItem("Jayesh"));
list->show();@ -
@class MyView : public QGraphicsView
{
Q_OBJECTpublic:
MyView(QGraphicsView *parent = 0) {QListWidget* list= new QListWidget(this); list->addItem(new QListWidgetItem("Banana")); list->addItem(new QListWidgetItem("Apple")); list->addItem(new QListWidgetItem("Orange")); list->addItem(new QListWidgetItem("Grapes")); list->addItem(new QListWidgetItem("Jayesh")); list->show(); }
}@
-
[quote author="Andre" date="1343143131"]So... is MyView created anywhere?
Note that it is not a good idea to put widget inside a QGraphicsView. It is possible, but chances are you'll run into issues.[/quote]
yes, in the main I had also a class that extends a QMainWindow and, inside it I create the MyView. If it is not a good idea how can I create a multi widget application?
-
Multi-widget is fine, but putting widgets inside a QGraphicsView is a source of problems. You're not actually doing that (yet), but based where you create your QListWidget (in the constructor of a QGraphicsView derived class), it seemed likely you'd like to do that.
-
without GraphicsView...
well, look at demos & examples:http://qt-project.org/doc/qt-4.8/examples-mainwindow.html -
That's the point: try to avoid doing that in the first place.
Anyway, for your first steps with the item view framework (including QListWidget), it would be good if you spare yourself the complications and just use the widget in a normal form to see how to work with it.