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. QWidget's child show doesn't work
QtWS25 Last Chance

QWidget's child show doesn't work

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 759 Views
  • 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 Offline
    M Offline
    Milosz
    wrote on 17 Aug 2018, 11:50 last edited by
    #1

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

    }

    J 1 Reply Last reply 17 Aug 2018, 12:04
    0
    • M Milosz
      17 Aug 2018, 11:50

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

      }

      J Online
      J Online
      JonB
      wrote on 17 Aug 2018, 12:04 last edited by
      #2

      @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
      0
      • M Offline
        M Offline
        Milosz
        wrote on 17 Aug 2018, 12:10 last edited by
        #3

        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;
        

        };

        J 1 Reply Last reply 17 Aug 2018, 12:14
        0
        • M Milosz
          17 Aug 2018, 12:10

          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;
          

          };

          J Online
          J Online
          JonB
          wrote on 17 Aug 2018, 12:14 last edited by
          #4

          @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
          0
          • M Offline
            M Offline
            Milosz
            wrote on 17 Aug 2018, 12:21 last edited by
            #5

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

            1 Reply Last reply
            1
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 17 Aug 2018, 17:37 last edited by
              #6

              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 Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              M 1 Reply Last reply 20 Aug 2018, 06:47
              1
              • Christian EhrlicherC Christian Ehrlicher
                17 Aug 2018, 17:37

                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.

                M Offline
                M Offline
                Milosz
                wrote on 20 Aug 2018, 06:47 last edited by
                #7

                @Christian-Ehrlicher No effect.
                :-(

                1 Reply Last reply
                0

                1/7

                17 Aug 2018, 11:50

                • Login

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