[英]QT4: Transparent Window with rounded corners
(我使用Qt::FramelessWindowHint
來禁用標准邊框)
我嘗試過樣式表,但是border-radius
和opacity
似乎對窗口沒有任何影響,它只適用於封閉小部件的子代。
我的第二個想法是使窗口完全透明(使用setWindowOpacity
),然后添加一個帶圓角的附加小部件(因為border-radius
適用於子級),然后將我的所有其他小部件分組到該小部件中。 但這不起作用,因為setWindowOpacity
影響所有孩子(我還沒有找到改變這種行為的方法)。
任何使我想到的外窗透明的方法(如樣式表opacity
)都不能正常工作(我只得到一個黑盒子而不是透明窗口)
任何幫助將受到高度贊賞。
我有一個類似的問題,我想在一個頂級小部件上繪畫,並且只顯示繪制的部分。 setWindowOpacity更改了繪制部分的不透明度,這是我不想要的。
this->setAttribute(Qt::WA_TranslucentBackground, true);
在沒有繪制部分的情況下更改了小部件的不透明度。 我只是試着扔一個按鈕,這也顯示完全不透明。 所以你應該能夠展示你喜歡的其他孩子。
我認為您應該使用小部件掩碼,如以下Qt中的示例所示:
http://doc.qt.io/qt-5/qtwidgets-widgets-shapedclock-example.html
我想你會找到你想要的東西!
希望這個對你有幫助!
void MainForm::resizeEvent(QResizeEvent * /* event */)
{
QImage image(this->size(), QImage::Format_Mono);
image.fill(0);
if(!this->isFullScreen() && !this->isMaximized())
{
image.setPixel(0, 0, 1); image.setPixel(1, 0, 1); image.setPixel(2, 0, 1); image.setPixel(3, 0, 1);
image.setPixel(0, 1, 1); image.setPixel(1, 1, 1);
image.setPixel(0, 2, 1);
image.setPixel(0, 3, 1);
image.setPixel(width() - 4, 0, 1); image.setPixel(width() - 3, 0, 1); image.setPixel(width() - 2, 0, 1); image.setPixel(width() - 1, 0, 1);
image.setPixel(width() - 2, 1, 1); image.setPixel(width() - 1, 1, 1);
image.setPixel(width() - 1, 2, 1);
image.setPixel(width() - 1, 3, 1);
image.setPixel(0, height() - 4, 1);
image.setPixel(0, height() - 3, 1);
image.setPixel(0, height() - 2, 1); image.setPixel(1, height() - 2, 1);
image.setPixel(0, height() - 1, 1); image.setPixel(1, height() - 1, 1); image.setPixel(2, height() - 1, 1); image.setPixel(3, height() - 1, 1);
image.setPixel(width() - 1, height() - 4, 1);
image.setPixel(width() - 1, height() - 3, 1);
image.setPixel(width() - 2, height() - 2, 1); image.setPixel(width() - 1, height() - 2, 1);
image.setPixel(width() - 4, height() - 1, 1); image.setPixel(width() - 3, height() - 1, 1); image.setPixel(width() - 2, height() - 1, 1); image.setPixel(width() - 1, height() - 1, 1);
}
this->setMask(QPixmap::fromImage(image));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.