Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QListWidget . First attempts

QListWidget . First attempts

Scheduled Pinned Locked Moved General and Desktop
15 Posts 3 Posters 4.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    blackbelt
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Peppy
      wrote on last edited by
      #2

      Did you set up parent/size of QListWidget?

      1 Reply Last reply
      0
      • B Offline
        B Offline
        blackbelt
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Peppy
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • B Offline
            B Offline
            blackbelt
            wrote on last edited by
            #5

            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 Reply Last reply
            0
            • P Offline
              P Offline
              Peppy
              wrote on last edited by
              #6
              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... :)
              1 Reply Last reply
              0
              • B Offline
                B Offline
                blackbelt
                wrote on last edited by
                #7

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

                }@

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    blackbelt
                    wrote on last edited by
                    #9

                    [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?

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        Peppy
                        wrote on last edited by
                        #11

                        without GraphicsView...
                        well, look at demos & examples:http://qt-project.org/doc/qt-4.8/examples-mainwindow.html

                        1 Reply Last reply
                        0
                        • B Offline
                          B Offline
                          blackbelt
                          wrote on last edited by
                          #12

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

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            andre
                            wrote on last edited by
                            #13

                            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.

                            1 Reply Last reply
                            0
                            • B Offline
                              B Offline
                              blackbelt
                              wrote on last edited by
                              #14

                              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)?

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                andre
                                wrote on last edited by
                                #15

                                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.

                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved