簡體   English   中英

在窗口QT外部填充背景

[英]Fill background outside window QT

我已經閱讀了文檔以及網站上的許多站點。 不幸的是,我沒有找到問題的答案。

是否有可能(我相信有機會)在彈出窗口之外填充背景? 讓我解釋一下:如果我的整個應用程序都具有類似分辨率為500x500 [px]的窗口,並且在中間創建了一個彈出窗口300x300-這意味着我在“父窗口”的每一側都有200 px。 有沒有機會(方法,標志)將背景填充為灰色?

圖片: https : //imgur.com/Hunev58

修改調色板即可完成工作。 顯示MessageBox時,這里的背景為紫色,單擊后即可恢復正常

#include <QApplication>
#include <QMainWindow>
#include <QVBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QMessageBox>
#include <QPalette>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QMainWindow w;

    QVBoxLayout mainLayout;
    QLabel foolabel("FooLabel");
    QPushButton foobutton("FooButton");
    mainLayout.addWidget(&foolabel);
    mainLayout.addWidget(&foobutton);
    QWidget window;
    window.setLayout(&mainLayout);
    w.setCentralWidget(&window);

    QPalette palette = QApplication::palette(&w);
    palette.setColor(QPalette::Inactive,QPalette::Window,QColor(138,43,226));
    w.setPalette(palette);

    w.show();

    QMessageBox box(&w);
    box.exec();

    return a.exec();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM