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();
    @



  • Did you set up parent/size of QListWidget?



  • actually no. Should I ? The snippet runs inside a QGraphicsView. Is there anything wrong with this



  • with this snippet? No, there is nothing wrong. But if you want to show anything inside QGraphicsView, I think, you will have to show us more...



  • 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();@



    1. set up parent for QListWidget. Just to make sure.
    2. show us more code... I promise, I don't say it to your mom... :)


  • @class MyView : public QGraphicsView
    {
    Q_OBJECT

    public:
    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();
       }
    

    }@



  • 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 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



  • So create a QWidget inside a QGraphicsView does not add it to QGraphicsView itself?



  • 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.



  • So this rule is valid for every kind of QWidget? The QPushButton for istance? is It safe to add a QWidget to the QMainWindow (does it make sense)?



  • I am only referring to putting widgets (any widget) in a QGraphicsView (so, using [[doc:QGrapicsProxyWidget]]). Putting a QpushBotton on a QmainWindow makes perfect sense, and has no issues.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.