Problem removing widgets from a layout
-
I use @ userAnswer->setFocus(Qt::OtherFocusReason); @ and still nothing. I check the status if it is focused using hasFocus()
-
can you show a bit more code? I assume the bug is somewhere else...
-
The layout
@
mapsLayout = new QVBoxLayout;
mapsLayout->setAlignment(Qt::AlignTop);@this is the function which sets visible the 3 widgets and as comment, I inserted the part from the init method:
@void MapsWidget::enterAnswer()
{
// //for entering the answer
// checkpointQuestion = new QLabel();
// checkpointQuestion->setWordWrap(true);
// checkpointQuestion->setStyleSheet("QLabel { background-color : #505050 ; color : white; }");
// checkpointQuestion->setAlignment(Qt::AlignCenter);// validateAnswer = new QPushButton();
// validateAnswer->setText("Ok");
// // validateAnswer->setMaximumWidth(50);// userAnswer = new QLineEdit();
// userAnswer->setStyleSheet("QLineEdit { background-color : #505050 ; color : white; }");
// userAnswer->setPlaceholderText("Enter answer here");
// userAnswer->setAlignment(Qt::AlignCenter);// connect(validateAnswer, SIGNAL( pressed() ), this, SLOT( checkAnswer()) );
// //end part for entering the answercheckpointQuestion->setText("Cum se numeste pizzeria cu nume italienesc?"); //set the text to the right one userAnswer->setFocus(); mapsLayout->setAlignment(validateAnswer, Qt::AlignCenter); mapsLayout->addWidget(checkpointQuestion); mapsLayout->addWidget(userAnswer); mapsLayout->addWidget(validateAnswer); checkpointQuestion->setVisible(true); validateAnswer->setVisible(true); userAnswer->setVisible(true); userAnswer->setFocus(Qt::OtherFocusReason); userAnswer->setFocus(Qt::MouseFocusReason); qDebug() << userAnswer->hasFocus();
}
@This is the code where they should be removed from the layout:
@void MapsWidget::checkAnswer()
{
qDebug() << userAnswer->text();mapsLayout->removeWidget(checkpointQuestion); mapsLayout->removeWidget(userAnswer); mapsLayout->removeWidget(validateAnswer); checkpointQuestion->setVisible(false); userAnswer->setVisible(false); validateAnswer->setVisible(false); answerCorectitude = new QPushButton(); mapsLayout->setAlignment(answerCorectitude, Qt::AlignCenter); connect(answerCorectitude, SIGNAL( pressed() ), this, SLOT( answerCorectitudeButton()) ); if (userAnswer->text() == "test") { answerCorectitude->setText("Correct answer!"); answerCorectitude->setVisible(true); mapsLayout->addWidget(answerCorectitude); } else { answerCorectitude->setText("Wrong answer!"); answerCorectitude->setVisible(true); mapsLayout->addWidget(answerCorectitude); }
}@
-
What OS are you using ? I did a little test in win 7 and it worked well.
-
I'm on Mac OS 10.6.8 with QTCreator 2.2.1.
Well, have you tried to hide them and then setVisible(true) again? -
Yes. ( + (setStyleSheet & setPlaceholder) )
-
hmm ... awkward. Maybe I should try my whole project on a windows machine .... could be the possibility that the simulator to be different?
-
Well, I have not fully tested your code. Just create one dialog with vertical layout, and add in this layout one button and one line edit. When the button was pressed, just remove the line edit from layout and set invisible, and if pressed again, show the line edit and added to layout. This "pseudocode" work well.
-
Well, ok. Thank you
-
dear comunity,
i have a problem with creating a layout be qtcreator, my clas is derivated from QMAinWindow and i create in the window three Greupboxes and a layout, but the layout not work, if i tray to make it window larger the group boxes have still the same size. here is the source code from the constructor.
@ this->set_DICS_Window_Positio(this);
this->set_Left_Up_Group_Box(this);
this->set_Right_Up_Group_Box(this);
this->set_Down_Box(this);this->ptr_all_QGroupBox = new QList<QGroupBox*>; this->set_all_Group_Boxes(); this->top_grid_layout = new QGridLayout; top_grid_layout->addWidget(this->left_Up_GroupBox, 0, 0); top_grid_layout->addWidget(this->right_Up_GroupBox, 0 , 1); top_grid_layout->addWidget(this->down_GroupBox, 1 , 0, 1, 2); top_grid_layout->addWidget(this); this->setLayout(top_grid_layout);
@
the Gruoboxes are created on this way in a separated function:
@ this->left_Up_GroupBox = new QGroupBox(ptr_MW);
this->left_Up_GroupBox->setGeometry(10, 10, 380, 280);
this->left_Up_GroupBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
@sorry for my bad english.
Thank you very much in advance for your answer.