Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QWidget's child show doesn't work

    General and Desktop
    3
    7
    361
    Loading More Posts
    • 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.
    • M
      Milosz last edited by

      I have a strange problem:
      My MainWindow is QWidget type and its constructor is like that:

      ...............
      loggingWidget = new QWidget;
      loggingWidget->setGeometry(0,0,1920,1080);
      loggingWidget->setStyleSheet("background-image: url(FinalOutput_01_10.png); border: none;");

      (1) QWidget *rulesWidget = new QWidget(loggingWidget);
      rulesWidget->setGeometry(200,200,1020,680);
      rulesWidget->setStyleSheet("background-image: url(FinalOutput.png); border: none;");

      rulesWidget->show();
      

      This operates OK.
      But when I inherite QWidget into RulesWidget class and line (1) is:
      RulesWidget *rulesWidget = new RulesWidget(loggingWidget);

      that show() doesn't work.

      definition of RulesWidget:
      class RulesWidget : public QWidget
      {
      Q_OBJECT
      public:
      explicit RulesWidget(QWidget *parent = nullptr);
      ......

      implementation
      RulesWidget::RulesWidget(QWidget *parent) : QWidget(parent)
      {

      }

      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @Milosz last edited by

        @Milosz said in QWidget's child show doesn't work:

        My MainWindow is QWidget type

        I thought it had to be QMainWindow type?

        loggingWidget = new QWidget;

        Where is its parent specified, or what is it added to?

        I don't know if these are relevant to your issue, but I wouldn't mind understanding them anyway...

        1 Reply Last reply Reply Quote 0
        • M
          Milosz last edited by

          Ok,
          so I show all the code

          MainWindow::MainWindow(QWidget *parent) :
          QWidget(parent)
          {

          this->setWindowFlags(Qt::CustomizeWindowHint);
          this->setGeometry(0,0,1920, 1080);
          loggingWidget = new QWidget;
          loggingWidget->setGeometry(0,0,1920,1080);
          loggingWidget->setStyleSheet("background-image: url(Ekran_01_FinalOutput_01_10.png); border: none;");
          
          
          RulesWidget *rulesWidget = new RulesWidget(loggingWidget);
          rulesWidget->setGeometry(200,200,1020,680);
          rulesWidget->setStyleSheet("background-image: url(Regulamin_FinalOutput.png); border: none;");
          
          
          rulesWidget->show();
          
          
          QHBoxLayout *mainLayout = new QHBoxLayout;
          mainLayout->addWidget(loggingWidget);
          
          setLayout(mainLayout);
          

          }

          and definition of MainWindow
          class MainWindow : public QWidget
          {
          Q_OBJECT

          public:
          explicit MainWindow(QWidget *parent = 0);
          ~MainWindow();

          private:

          QWidget *loggingWidget;
          

          };

          JonB 1 Reply Last reply Reply Quote 0
          • JonB
            JonB @Milosz last edited by

            @Milosz
            At least that makes sense now!

            Again, I don't know, but you call rulesWidget->show(); before you have ever added it (or anything) to the main window. I wouldn't even try to do that, seems real odd to me, can a widget deal with show() when it's not anywhere on the page? Does it make any difference if you put that as the very last line?

            1 Reply Last reply Reply Quote 0
            • M
              Milosz last edited by

              I marked it's strange (:-)).
              I have put it at the very last line but no effect :-(

              1 Reply Last reply Reply Quote 1
              • Christian Ehrlicher
                Christian Ehrlicher Lifetime Qt Champion last edited by

                I would guess you have not implemented sizeHint() and therefore QWidget::sizeHint() is called which simply returns and invalid size since it doesn't know better.

                Qt has to stay free or it will die.

                M 1 Reply Last reply Reply Quote 1
                • M
                  Milosz @Christian Ehrlicher last edited by

                  @Christian-Ehrlicher No effect.
                  :-(

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post