久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使 QWidget 透明

Make QWidget transparent(使 QWidget 透明)
本文介紹了使 QWidget 透明的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有一個(gè)基于 QWidget 的覆蓋小部件,它應(yīng)該繪制一些文本并在我的應(yīng)用程序的中央小部件上進(jìn)行.問題是我無法將覆蓋小部件的背景設(shè)置為透明.我已經(jīng)嘗試過的:

I have a QWidget-based overlay widget which should paint some text and take place over the central widget of my application. The problem is that I can't set background of overlay widget to be transparent. What I already tried:

  1. setPalette(Qt::transparent);
  2. setAttribute( Qt::WA_TranslucentBackground, true );
  3. setAttribute( Qt::WA_OpaquePaintEvent, true );
  4. setAutoFillBackground(false);
  5. setStyleSheet("QWidget{background-color: transparent;}");
  6. setAttribute(Qt::WA_NoSystemBackground);

推薦答案

我最好的猜測是顯示覆蓋小部件,將小部件轉(zhuǎn)換為窗口,調(diào)整其大小以適應(yīng)其內(nèi)容,然后手動(dòng)將它們移動(dòng)到所需位置.

My best guess to show an overlay widget, is convert the widget to a window, resize it to it's contents and move them to the desired position manually.

>

MainWindow 示例,在視頻小部件的中心顯示覆蓋小部件:

MainWindow Example, showing the overlay widget in the center of the video widget:

Mwindow::Mwindow()
{
    widget = new Widget(this);
}

void Mwindow::widgetSizeMove()
{
    if (widget->width() <= videoWidget->width() && widget->height() <= videoWidget->height())
    {
        widget->setWindowOpacity(1); // Show the widget
        QPoint p = videoWidget->mapToGlobal(videoWidget->pos());
        int x = p.x() + (videoWidget->width() - widget->width()) / 2;
        int y = p.y() + (videoWidget->height() - widget->height()) / 2;
        widget->move(x, y);
        widget->raise();
    }
    else
    {
        widget->setWindowOpacity(0); // Hide the widget
    }
}

bool Mwindow::event(QEvent *event)
{
    switch (event->type())
    {
    case QEvent::Show:
        widget->show();
        QTimer::singleShot(50, this, SLOT(widgetSizeMove())); 
        //Wait until the Main Window be shown
        break;
    case QEvent::WindowActivate:
    case QEvent::Resize:
    case QEvent::Move:
        widgetSizeMove();
        break;
    default:
        break;
    }

    return QMainWindow::event(event);
}

小部件示例:

Widget::Widget(QWidget *parent) : QWidget(parent)
{
    setWindowFlags(Qt::Window | Qt::FramelessWindowHint);

    setAttribute(Qt::WA_NoSystemBackground);
    setAttribute(Qt::WA_TranslucentBackground);
    setAttribute(Qt::WA_PaintOnScreen);

    setAttribute(Qt::WA_TransparentForMouseEvents);
}

void Widget::paintEvent(QPaintEvent*)
{
    QPainter p(this);
    QString text = "Some foo goes here";
    QFontMetrics metrics(p.font());
    resize(metrics.size(0, text));
    p.drawText(rect(), Qt::AlignCenter, text);
}

使用 LibVLC 顯示視頻的示例:

Example when showing a video with LibVLC:

這篇關(guān)于使 QWidget 透明的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數(shù)據(jù)?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環(huán): for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環(huán)?)
Reusing thread in loop c++(在循環(huán) C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環(huán)形?)
主站蜘蛛池模板: 国产在线永久免费 | 911精品国产 | 巨大荫蒂视频欧美另类大 | 欧美成人精品激情在线观看 | 欧美五月婷婷 | 成人一区二区视频 | 免费观看的黄色网址 | 一级二级三级黄色 | 久久99久久99久久 | 国产精品福利久久久 | 99久9| 天天色影视综合 | 国产精品自拍av | 中文av在线播放 | h片在线免费观看 | 亚洲欧美一区二区三区在线 | 91色在线 | 亚洲国产高清高潮精品美女 | 欧美国产精品一区二区三区 | 久久精品99国产精品 | 天天干天天操天天射 | 午夜激情影院 | 欧美精品导航 | 日韩高清成人 | 暖暖日本在线视频 | 欧美激情精品久久久久久变态 | 久久久久91 | 亚洲少妇综合网 | 久久午夜国产精品www忘忧草 | 成人午夜在线观看 | 久久久久久久久久一区 | 精品在线播放 | 黄网站在线观看 | 激情亚洲 | 国产精品乱码一区二三区小蝌蚪 | 亚洲精品久久久一区二区三区 | 亚洲性网 | 国产精品 欧美精品 | 欧美亚洲视频在线观看 | 日韩高清不卡 | 国产福利资源在线 |