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. Adding layout to Qdialog changes the layout in an other Qdialog
QtWS25 Last Chance

Adding layout to Qdialog changes the layout in an other Qdialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
layoutqdialog
7 Posts 3 Posters 6.6k 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.
  • G Offline
    G Offline
    gabor53
    wrote on last edited by
    #1

    Hi,
    I have 2 QDialogs: Additem and Review.

    //Add buttons
               ReviewButton = new QPushButton(tr("&Review"));
    
               ReviewButton->setStyleSheet ("QPushButton{"
                                            "background-color: rgb(0, 255, 0);"
                                            "border-style: outset;"
                                            "border-width: 2px;"
                                            "border-radius: 10px;"
                                            "border-color: beige;"
                                            "font: bold 14px;"
                                            "min-width: 10em;"
                                            "padding: 6px;}"
                                            );
            ReviewButton->setToolTip ("<b><font size='12'><font color = 'blue'>Click to review your entries.</font></b>");
    		ReviewButton->setFixedWidth (100);
    
    
            connect(ReviewButton,SIGNAL(clicked(bool)),this,SLOT(review()));
    
            reset_Button = new QPushButton(tr("&Reset"));
    
            reset_Button->setStyleSheet ("QPushButton{"
                                            "background-color: rgb(255, 0, 0);"
                                            "border-style: outset;"
                                            "border-width: 2px;"
                                            "border-radius: 10px;"
                                            "border-color: beige;"
                                            "font: bold 14px;"
                                            "min-width: 10em;"
                                            "padding: 6px;}"
                                            );
    
            reset_Button->setToolTip ("<b><font size='12'><font color = 'blue'>Click to reset all the fields. This will close the window and clear all your entries.</font></b>");
    		reset_Button->setMaximumWidth (100);
            button_Layout->addWidget (ReviewButton);
            button_Layout->addWidget (reset_Button);
    
            connect (reset_Button,SIGNAL(clicked(bool)),this,SLOT(resetAll()));
    
    //Add title
    
            QLabel* title = new QLabel;
            title->setText("Add a Friend To the Database");
            title->setAlignment(Qt::AlignCenter);
            QFont f( "Arial", 18, QFont::Bold);
            title->setFont(f);
    
    //Add layout
    
            titleLayout->addWidget (title);
    
            scroll->setWidgetResizable (true);
            scroll->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
            scroll->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
    
            grid->setColumnMinimumWidth (1,20);
            grid->setVerticalSpacing (15);
            grid->verticalSpacing ();
    
            name_Layout->addWidget (LineEdit_Name);
            name_Layout->addWidget (angry_image_Label);
            name_Layout->addWidget (incorrect_Label);
            name_Layout->insertSpacing (1,15);
            name_Layout->insertSpacing (2,15);
    
            QWidget *viewport = new QWidget(this);
            scroll->setWidget (viewport);
            scroll->setWidgetResizable (true);
            spacer1->setText ("             ");
    
    		grid->addWidget (Label_ID,0,0,1,1,Qt::AlignTop);
            grid->addWidget (ID_Display,0,1,1,1,Qt::AlignTop);
            grid->addWidget (Label_Name,1,0,1,1,Qt::AlignTop);
            grid->addLayout (name_Layout,1,1,1,1,Qt::AlignTop);
    
            grid->addLayout (button_Layout,3,1,1,1,Qt::AlignCenter);
    
            scroll->setLayout (grid);
    
    
            mainLayout->addLayout (titleLayout);
            mainLayout->addWidget (scroll);
    
            Additem::setLayout (mainLayout);
    
    }
    
    void Additem::readAndValidate()
    {
        name = LineEdit_Name->text ();
    
        angry_image_Label->setFixedSize (30,30);
        incorrect_Label->setStyleSheet("QLabel { font-size:18px; color: red; }");
    
                     if(name.length ()<2)
                       {
                          incorrect_Label->setText ("The name is too short!");
    
                          QPixmap pix("C:/Programming/Projects/Folkfriends/icons/angry.png");
    
                           angry_image_Label->setScaledContents (true);
                           angry_image_Label->setPixmap (pix);
                       }
                       else
                       {
                           incorrect_Label->setText ("");
                           QPixmap pix2("C:/Programming/Projects/FolkFriends/icons/Check-icon.png");
                           angry_image_Label->setScaledContents (true);
                           angry_image_Label->setPixmap (pix2);
                       }
    
                   qDebug() << " Name in function: " << name;
    
    }
    
    void Additem::review()
    {
        revName_Label->setText ("<font size = '12' color = 'blue'>"+name+"</font>");
    
        Review->setWindowTitle ("Review Friend's Data");
    
        QFont f( "Arial", 18, QFont::Bold);
        QFont g( "Arial", 16, QFont::Normal);
    
        rev_Title_Lbl->setFont (f);
        rev_Title_Lbl->setText ("Review the Data You Entered");
        rev_Title->addWidget (rev_Title_Lbl,Qt::AlignHCenter);
    
        rev_Grid->addLayout (rev_Title,0,0,1,1,Qt::AlignTop);
        rev_Grid->addWidget (Label_ID,2,0,1,1,Qt::AlignTop);
        rev_Grid->addWidget (ID_Display,2,1,1,1,Qt::AlignTop);
        rev_Grid->addWidget (Label_Name,3,0,1,1,Qt::AlignTop);
        rev_Grid->addWidget (revName_Label,3,1,1,1,Qt::AlignTop);
    
    //    Review->setLayout (rev_VLayout);
    
    //    rev_VLayout->addLayout (rev_Grid);
    
        Review->exec ();
    }
    
    void Additem::resetAll()
    {
       qDebug()  << "Resetting";
    }
    

    When I add

    //    Review->setLayout (rev_VLayout);
    
    //    rev_VLayout->addLayout (rev_Grid);
    

    Review displays everything correctly, but Additem changes its layout:
    name_Layout moves from position 1,1 to 0,0 and covers up Label_ID.
    Please help me figure out why.
    Thank you.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      How are you creating these two layouts ?

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

      G 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        How are you creating these two layouts ?

        G Offline
        G Offline
        gabor53
        wrote on last edited by
        #3

        @SGaist
        Hi,
        Using grid layout.

        G 1 Reply Last reply
        0
        • G gabor53

          @SGaist
          Hi,
          Using grid layout.

          G Offline
          G Offline
          gabor53
          wrote on last edited by
          #4

          Same happens when I use QHBoxLayout in Review which is a QDialog.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Can you share the code where you create and setup these two layouts ?

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

            G 1 Reply Last reply
            0
            • SGaistS SGaist

              Can you share the code where you create and setup these two layouts ?

              G Offline
              G Offline
              gabor53
              wrote on last edited by
              #6

              @SGaist
              Hi,
              Here is the code:
              additem.cpp
              Thank you for your help.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                alex_malyu
                wrote on last edited by alex_malyu
                #7

                @gabor53 :

                You change the widget geometry in a way it affects hints. so layout has to be updated.
                From the top of my head it might be enough to call the following updateGeometry() on every affected widget. Aka:

                Actually I take it back.
                If you could show your ui->setupUi(this); code I could probably say more, but as for now it seems you are trying to use the same layout in different dialogs. Make sure you do not.

                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