Hi ChrisW67 and thanks a lot for all the solutions you are providing me.
It is true that using a QMessageBox and then delete its layout is quite ugly. I don't like that either but I need the addButton() and buttonClicked() methods.
Both your options work but I am having trouble finding out what my error is in my code and where it comes from. I'm really sorry, I feel quite bad not being able to use your perfectly suited and simple solutions to my simple issue ...
So please let me paste more code (the whole message box construction and when it is triggered) :
// Brightness parameters setup
delete choiceBoxB.layout();
choiceBoxB.setLayout(choiceBoxBLayout);
choiceBoxBMessage
= new QLabel("Choisissez le pourcentage de luminosite souhaitee :");
sliderPosB
= new QLabel("100%");
percentageSliderB
= new QSlider(Qt
::Horizontal);
percentageSliderB->setMinimum(0);
percentageSliderB->setMaximum(200);
percentageSliderB->setSliderPosition(100);
connect(percentageSliderB,SIGNAL(valueChanged(int)),this,SLOT(updateSliderBPos(int)));
choiceBoxBLayout->addWidget(choiceBoxBMessage);
choiceBoxBLayout->addWidget(sliderPosB);
choiceBoxB.
addButton(bCancelB,
QMessageBox::RejectRole);
choiceBoxBLayout->addWidget(percentageSliderB);
choiceBoxBLayout->addWidget(bOkB);
choiceBoxBLayout->addWidget(bCancelB);
// Brightness parameters setup
delete choiceBoxB.layout();
choiceBoxBLayout = new QVBoxLayout;
choiceBoxB.setLayout(choiceBoxBLayout);
choiceBoxBMessage = new QLabel("Choisissez le pourcentage de luminosite souhaitee :");
sliderPosB = new QLabel("100%");
percentageSliderB = new QSlider(Qt::Horizontal);
bOkB = new QPushButton("&Ok");
bCancelB = new QPushButton("&Annuler");
percentageSliderB->setMinimum(0);
percentageSliderB->setMaximum(200);
percentageSliderB->setSliderPosition(100);
connect(percentageSliderB,SIGNAL(valueChanged(int)),this,SLOT(updateSliderBPos(int)));
choiceBoxBLayout->addWidget(choiceBoxBMessage);
choiceBoxBLayout->addWidget(sliderPosB);
choiceBoxB.addButton(bOkB,QMessageBox::AcceptRole);
choiceBoxB.addButton(bCancelB,QMessageBox::RejectRole);
choiceBoxBLayout->addWidget(percentageSliderB);
choiceBoxBLayout->addWidget(bOkB);
choiceBoxBLayout->addWidget(bCancelB);
To copy to clipboard, switch view to plain text mode
and the slot that triggers choiceBoxB's execution (connected to a menu option, it works) :
void mainFrame::changeBrightness() {
if(currentImage.getBuffer() != NULL){
choiceBoxB.exec();
if(choiceBoxB.clickedButton()->text() == bOkB->text()){ // I know, this is even uglier ...
/* I am using quick and ugly solutions concerning the GUI because those are details in my project which is a duplicata of a GTK & C project. */
currentImage.changeBrightness(percentageSliderB->value());
displayImage(currentImage);
}
}
}
void mainFrame::changeBrightness() {
if(currentImage.getBuffer() != NULL){
choiceBoxB.exec();
if(choiceBoxB.clickedButton()->text() == bOkB->text()){ // I know, this is even uglier ...
/* I am using quick and ugly solutions concerning the GUI because those are details in my project which is a duplicata of a GTK & C project. */
currentImage.changeBrightness(percentageSliderB->value());
displayImage(currentImage);
}
}
}
To copy to clipboard, switch view to plain text mode
I have also discovered an interesting thing.
As you can see now my message box elements also contain a message.
I tried modifying the updateSliderBPos function from
void updateSliderBPos(int value) {
sliderPosB
->setText
(QString("%1%").
arg(value
));
}
void updateSliderBPos(int value) {
sliderPosB->setText(QString("%1%").arg(value));
}
To copy to clipboard, switch view to plain text mode
to :
void updateSliderBPos(int value) {
sliderPosB
->setText
(QString("%1%").
arg(value
));
choiceBoxBMessage
->setText
(QString("%1%").
arg(value
));
}
void updateSliderBPos(int value) {
sliderPosB->setText(QString("%1%").arg(value));
choiceBoxBMessage->setText(QString("%1%").arg(value));
}
To copy to clipboard, switch view to plain text mode
The choiceBoxBMessage is updated with the correct position of the slider (plus the percentage symbol) whereas the sliderPosB isn't.
The sliderPosB label's purpose is only to show the slider position in that box. I do not see what differences there could be with the choiceBoxBMessage label ...
Again thanks for your help,
Faradn
Bookmarks