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. No widget is shown, strangely
Qt 6.11 is out! See what's new in the release blog

No widget is shown, strangely

Scheduled Pinned Locked Moved Unsolved General and Desktop
22 Posts 7 Posters 6.2k Views 4 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.
  • tomyT Offline
    tomyT Offline
    tomy
    wrote on last edited by
    #9

    Thank you all very much.

    I think QMainWindow is not acting as a widget, the way I'm familiar with widgets; it mostly works as an application window, in that sense that we, for instance, can put a widget, like a QPushButon, onto a QFormLayout or another widget without coming another widget to the scene, but this for QMainWindow differs.

    Special widgets like QMainWindow are application windows logically, as far as I'm concerned (up to now).
    But now I know we have dozens of Qt widgets on the list above (and it needs much much time to know them and recall the one needed when the developer is coding their project! ¯_(ツ)_/¯ ). The question is, where is the list of those special widgets (or better to say, containers —apart from QVector and so on)?

    jsulmJ 1 Reply Last reply
    0
    • tomyT Offline
      tomyT Offline
      tomy
      wrote on last edited by
      #10

      Other question, for the example, is in the test_1.cpp:

      void test_1::updateStatus() {
          int completedCount = 0;
          
          for(auto t: mTasks)
              if(t->isCompleted())
                  completedCount++;
      
          int todoCount = mTasks.size() - completedCount;
          statusLabel->setText(QString("Statuse: %1 todo / %2 completed")
                               .arg(todoCount)
                               .arg(completedCount));
      }
      

      t is of the class test_1 but how could it have called a method, bool isCompleted() const;, from another class, task?

      jsulmJ 1 Reply Last reply
      0
      • tomyT tomy

        Thank you all very much.

        I think QMainWindow is not acting as a widget, the way I'm familiar with widgets; it mostly works as an application window, in that sense that we, for instance, can put a widget, like a QPushButon, onto a QFormLayout or another widget without coming another widget to the scene, but this for QMainWindow differs.

        Special widgets like QMainWindow are application windows logically, as far as I'm concerned (up to now).
        But now I know we have dozens of Qt widgets on the list above (and it needs much much time to know them and recall the one needed when the developer is coding their project! ¯_(ツ)_/¯ ). The question is, where is the list of those special widgets (or better to say, containers —apart from QVector and so on)?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by jsulm
        #11

        @tomy said in No widget is shown, strangely:

        I think QMainWindow is not acting as a widget, the way I'm familiar with widgets; it mostly works as an application window, in that sense that we, for instance, can put a widget, like a QPushButon, onto a QFormLayout or another widget without coming another widget to the scene, but this for QMainWindow differs.

        That's because QMainWindow has a widgets called Central Widget in its central part.

        "The question is, where is the list of those special widgets (or better to say, containers —apart from QVector and so on)?" - in the documentation: https://doc.qt.io/qt-5/containers.html Also, containers do not have anything to do with widgets.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        tomyT 1 Reply Last reply
        0
        • tomyT tomy

          Other question, for the example, is in the test_1.cpp:

          void test_1::updateStatus() {
              int completedCount = 0;
              
              for(auto t: mTasks)
                  if(t->isCompleted())
                      completedCount++;
          
              int todoCount = mTasks.size() - completedCount;
              statusLabel->setText(QString("Statuse: %1 todo / %2 completed")
                                   .arg(todoCount)
                                   .arg(completedCount));
          }
          

          t is of the class test_1 but how could it have called a method, bool isCompleted() const;, from another class, task?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #12

          @tomy said in No widget is shown, strangely:

          t is of the class test_1 but how could it have called a method, bool isCompleted() const;, from another class, task?

          Like any other method of a class? If updateStatus() is not static you need an instance of test_1 to call any public method on it...

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          tomyT 1 Reply Last reply
          0
          • jsulmJ jsulm

            @tomy said in No widget is shown, strangely:

            t is of the class test_1 but how could it have called a method, bool isCompleted() const;, from another class, task?

            Like any other method of a class? If updateStatus() is not static you need an instance of test_1 to call any public method on it...

            tomyT Offline
            tomyT Offline
            tomy
            wrote on last edited by
            #13

            @jsulm

            Like any other method of a class? If updateStatus() is not static you need an instance of test_1 to call any public method on it...

            Both t (mTask vector) and updatestatus() are of the same class test_1, whilest iscompleted() is a method of the class task (the whole example is above, in the first post and it works right!)

            That QVector<Task*> mTasks; private data member can at the upmost level call other private/public data members/methods of the same class not another class just because that new class is also added to the project. I mean there should be a way to call them, if my recollection is accurate. Will "include task.h" work it out!?

            jsulmJ 1 Reply Last reply
            0
            • tomyT tomy

              @jsulm

              Like any other method of a class? If updateStatus() is not static you need an instance of test_1 to call any public method on it...

              Both t (mTask vector) and updatestatus() are of the same class test_1, whilest iscompleted() is a method of the class task (the whole example is above, in the first post and it works right!)

              That QVector<Task*> mTasks; private data member can at the upmost level call other private/public data members/methods of the same class not another class just because that new class is also added to the project. I mean there should be a way to call them, if my recollection is accurate. Will "include task.h" work it out!?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #14

              @tomy said in No widget is shown, strangely:

              data members/methods of the same class not another class just because that new class is also added to the project. I mean there should be a way to call them

              I don't understand the problem: you can call methods of other classes in a class as long as you have instances of that class:

              void ClassA::someMethod()
              {
                  ClassB classB;
                  classB.someMethodInClassB();
              }
              

              So, what is the problem?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              tomyT 1 Reply Last reply
              1
              • jsulmJ jsulm

                @tomy said in No widget is shown, strangely:

                I think QMainWindow is not acting as a widget, the way I'm familiar with widgets; it mostly works as an application window, in that sense that we, for instance, can put a widget, like a QPushButon, onto a QFormLayout or another widget without coming another widget to the scene, but this for QMainWindow differs.

                That's because QMainWindow has a widgets called Central Widget in its central part.

                "The question is, where is the list of those special widgets (or better to say, containers —apart from QVector and so on)?" - in the documentation: https://doc.qt.io/qt-5/containers.html Also, containers do not have anything to do with widgets.

                tomyT Offline
                tomyT Offline
                tomy
                wrote on last edited by
                #15

                @jsulm

                That's because QMainWindow has a widgets called Central Widget in its central part.

                So worse! It mustn't need another QWidget to be instantiated like in the posts #2, #3. And we should've been able to put the controls directly on it. But it sounds that, it's not a real central widget, but a place/room, that "must" be filled by another widget! :(

                "The question is, where is the list of those special widgets (or better to say, containers —apart from QVector and so on)?" - in the documentation: https://doc.qt.io/qt-5/containers.html Also, containers do not have anything to do with widgets.

                No, I didn't mean that indeed, although that link was also nifty. :)
                I mean those widget/application windows containers like QMainWindow. That work as scaffolding covering the whole project and also need some widgets to be added to be able to put other controls on them, like the one above.

                jsulmJ 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @tomy said in No widget is shown, strangely:

                  data members/methods of the same class not another class just because that new class is also added to the project. I mean there should be a way to call them

                  I don't understand the problem: you can call methods of other classes in a class as long as you have instances of that class:

                  void ClassA::someMethod()
                  {
                      ClassB classB;
                      classB.someMethodInClassB();
                  }
                  

                  So, what is the problem?

                  tomyT Offline
                  tomyT Offline
                  tomy
                  wrote on last edited by tomy
                  #16

                  @jsulm

                  I don't understand the problem: you can call methods of other classes in a class as long as you have instances of that class:

                  void ClassA::someMethod()
                  {
                      ClassB classB;
                      classB.someMethodInClassB();
                  }
                  

                  So, what is the problem?

                  I know that.
                  Oh, so sorry. The vector contains instances of the class Task. :)
                  I don't know why I didn't note that, I must have been out of my mind!

                  1 Reply Last reply
                  0
                  • tomyT tomy

                    @jsulm

                    That's because QMainWindow has a widgets called Central Widget in its central part.

                    So worse! It mustn't need another QWidget to be instantiated like in the posts #2, #3. And we should've been able to put the controls directly on it. But it sounds that, it's not a real central widget, but a place/room, that "must" be filled by another widget! :(

                    "The question is, where is the list of those special widgets (or better to say, containers —apart from QVector and so on)?" - in the documentation: https://doc.qt.io/qt-5/containers.html Also, containers do not have anything to do with widgets.

                    No, I didn't mean that indeed, although that link was also nifty. :)
                    I mean those widget/application windows containers like QMainWindow. That work as scaffolding covering the whole project and also need some widgets to be added to be able to put other controls on them, like the one above.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by jsulm
                    #17

                    @tomy said in No widget is shown, strangely:

                    But it sounds that, it's not a real central widget, but a place/room, that "must" be filled by another widget! :(

                    Wrong. There is already a widget by default which you can get using https://doc.qt.io/qt-5/qmainwindow.html#centralWidget
                    If you, for some reason, want to set your own widget you can do so as well: https://doc.qt.io/qt-5/qmainwindow.html#setCentralWidget

                    QMainWindow simply provides functionality you need in an application window. A QWidget is simply a base class for all widgets and does not (and should not) contain functionality needed in a main window of an application.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    SGaistS 1 Reply Last reply
                    1
                    • jsulmJ jsulm

                      @tomy said in No widget is shown, strangely:

                      But it sounds that, it's not a real central widget, but a place/room, that "must" be filled by another widget! :(

                      Wrong. There is already a widget by default which you can get using https://doc.qt.io/qt-5/qmainwindow.html#centralWidget
                      If you, for some reason, want to set your own widget you can do so as well: https://doc.qt.io/qt-5/qmainwindow.html#setCentralWidget

                      QMainWindow simply provides functionality you need in an application window. A QWidget is simply a base class for all widgets and does not (and should not) contain functionality needed in a main window of an application.

                      SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #18

                      @jsulm said in No widget is shown, strangely:

                      Wrong. There is already a widget by default which you can get using https://doc.qt.io/qt-5/qmainwindow.html#centralWidget

                      Just to clear one thing, as noted in the documentation, by default there is no central widget. You may have one though when using Designer as it might be added automagically for you.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      2
                      • tomyT Offline
                        tomyT Offline
                        tomy
                        wrote on last edited by
                        #19

                        Another question,
                        Please take a look at the following method of the example:

                        void test_1::addTask() {
                           bool ok;
                           QString name = QInputDialog::getText(this, tr("Add Task"), tr("Task name"),
                                                                QLineEdit::Normal, tr("Untitled task"), &ok);
                        
                           if(ok && !name.isEmpty()) {
                               Task* task = new Task(name);
                               connect(task, &Task::removed, this, &test_1::removeTask);
                               connect(task, &Task::statusChanged, this, &test_1::taskStatusChanged);
                               mTasks.append(task);
                               verticalTasksLayout->addWidget(task);
                               updateStatus();
                           }
                        }
                        

                        Both connections are right and work correctly, inside the if condition, but my question is couldn't we declare those two connections somewhere else so that they're more general and not specifically inside that condition?

                        Declaring the connections inside a condition to my eyes looks rather weird! What are your opinions, please?

                        1 Reply Last reply
                        0
                        • mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #20

                          Hi
                          Perfectly normal.
                          The connect statements are part of the new Task creation so its natural place to have them near where the instance is created.
                          if no new task is created, then no connection needed

                          tomyT 1 Reply Last reply
                          2
                          • mrjjM mrjj

                            Hi
                            Perfectly normal.
                            The connect statements are part of the new Task creation so its natural place to have them near where the instance is created.
                            if no new task is created, then no connection needed

                            tomyT Offline
                            tomyT Offline
                            tomy
                            wrote on last edited by
                            #21

                            @mrjj
                            But it's sort of repetitive, isn't it?
                            We here declare the connections once again each time a new task is created, while the whole connections' concept is a sole thing, I surmise.

                            mrjjM 1 Reply Last reply
                            0
                            • tomyT tomy

                              @mrjj
                              But it's sort of repetitive, isn't it?
                              We here declare the connections once again each time a new task is created, while the whole connections' concept is a sole thing, I surmise.

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #22

                              @tomy
                              Oh no.
                              A connection is pr instance .
                              Meaning, if you want every task to be able to report "statusChanged" then
                              each must be connected.
                              Its not as a type thing. Its from real object to real object.
                              So all must be connected.

                              1 Reply Last reply
                              2

                              • Login

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