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

使 QWidget 透明

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

問題描述

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

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);

推薦答案

我最好的猜測是顯示覆蓋小部件,將小部件轉換為窗口,調整其大小以適應其內容,然后手動將它們移動到所需位置.

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:

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

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

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 日韩欧美在线观看 | 欧美亚洲在线视频 | 欧美中文视频 | 日本精品一区二区三区在线观看视频 | 欧美一级电影免费观看 | 亚洲欧美日韩精品久久亚洲区 | 亚洲91| 国产精品久久久久久久久久三级 | 亚洲精品久久久久久一区二区 | 亚洲欧美另类在线 | 久久精品无码一区二区三区 | 精品国产一区二区久久 | 日韩一区二区在线播放 | 天天操天天射综合网 | 正在播放国产精品 | 一区二区精品 | av激情影院 | 欧美日韩在线一区二区三区 | 久久久久国色av免费观看性色 | 欧美成人免费在线视频 | 久久综合一区二区三区 | www.成人.com | 五月婷婷 六月丁香 | a中文在线视频 | 日韩久久久久久 | gav成人免费播放视频 | av综合站 | 在线欧美a | 国产乱码精品一区二区三区五月婷 | 日本一区精品 | 国产不卡一区 | 伦理二区 | 成人午夜在线视频 | 久视频在线观看 | 日韩中文字幕一区二区 | 免费成人高清在线视频 | www国产亚洲精品久久网站 | 成人性生交大免费 | 日韩三区在线观看 | 亚洲成人999| www.久久久久久久久 |