简体   繁体   中英

Stylesheet a QInputDialog

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:

在此处输入图片说明

After:

在此处输入图片说明

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

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:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM