Stylesheet a QInputDialog

4.7k views Asked by At

Is it possible to style a QinputDialog?

I have the following code:

void calibratemotors::on_pushButton_shuttopen_manualent_clicked()
{
    bool ok;
    double shutopen_manenter = QInputDialog::getDouble(this, "getDouble",
                                       "Some Number:", 0.00, -10000, 10000, 2, &ok);
    if (ok)
        ui->label->setText(QString("%1").arg(shutopen_manenter));

}

The problem is, is it inherits aspects of "this", such as the background colour, border, etc. I tried to add the line:

this->setStyleSheet( "QInputDialog {background-color: red;}" );

on the click but that also changes the parent window as well, so is it possible to only trigger say the QInputDialog's background colour without effecting the parent? Right now I am getting this:

Before:

enter image description here

After:

enter image description here

Its like the background of the parent is being stripped and reverted back to default system colors.

1

There are 1 answers

0
eyllanesc On BEST ANSWER

Uses QInputDialog instead of QMenu. In this case setStyleSheet( "QInputDialog {background-color: red;}" );. A good practice is to indicate the widget to which it will affect. According to what you tell me your base widget is QDialog.

The "*" makes the style only apply to that widget and does not cascade to the others.

Here's an example.

setStyleSheet( "QDialog{background-color: black;}"
                   "QInputDialog {background-color: red;};");

ui->label->setStyleSheet("*{background-color: green;}");

Output:

enter image description here