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

無框透明窗qt5

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

問題描述

我對 qt 和 C++ 很陌生,但遇到了一個我似乎無法弄清楚的問題.當我單擊主 ui 上的按鈕時,我想打開一個無框且透明的窗口.當我按下主用戶界面上的按鈕時,我的代碼可以打開一個新窗口,但我似乎無法讓無框和透明部分工作.

I'm quite new to qt and c++ and I've encountered a problem that I can't seem to figure out. I'm wanting to open a frameless and transparent window when I click a button on the main ui. I've got the code working to open a new window when I press a button on the main ui but I can't seem to get the frameless and transparent part working.

這里是我為了學習這個而寫的小程序的源碼

Here is the source codes for the small program that I wrote to learn this

main.cpp

#include "learnwindow.h"
#include <QApplication>

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

    return a.exec();
}

這里是 LearnWindow.h

Here is the LearnWindow.h

#ifndef LEARNWINDOW_H
#define LEARNWINDOW_H

#include <QMainWindow>
#include <transwindow.h>

namespace Ui {
class LearnWindow;
}

class LearnWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit LearnWindow(QWidget *parent = 0);
    ~LearnWindow();

private slots:
    void on_pushButton_clicked();

private:
    Ui::LearnWindow *ui;
    TransWindow *winTrans;

public slots:
    void openTrans();
};

#endif // LEARNWINDOW_H

這里是learnwindow.cpp

Here is learnwindow.cpp

#include "learnwindow.h"
#include "ui_learnwindow.h"

LearnWindow::LearnWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::LearnWindow)
{
    ui->setupUi(this);
}

LearnWindow::~LearnWindow()
{
    delete ui;
}

void LearnWindow::openTrans()
{
    winTrans = new TransWindow (this);
    //winTrans->setWindowTitle("NewWin");
   // winTrans->setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
    //winTrans->setAttribute(Qt::WA_TranslucentBackground,true);
    //winTrans->setAutoFillBackground(false);
    //winTrans->setStyleSheet("background:transparent;");
    winTrans->show();
}

void LearnWindow::on_pushButton_clicked()
{
    openTrans();
}

這里是transwindow.h

Here is the transwindow.h

#ifndef TRANSWINDOW_H
#define TRANSWINDOW_H

#include <QDialog>

namespace Ui {
class TransWindow;
}

class TransWindow : public QDialog
{
    Q_OBJECT

public:
    explicit TransWindow(QWidget *parent = 0);

    //setWindowFlags(windowFlags()| Qt::FramelessWindowHint);

    ~TransWindow();

private:
    Ui::TransWindow *ui;
};

#endif // TRANSWINDOW_H

這里是 transwindow.cpp

And here is transwindow.cpp

#include "transwindow.h"
#include "ui_transwindow.h"

TransWindow::TransWindow(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::TransWindow)
{
    //setWindowTitle("NewWin");
    //setWindowFlags(Qt::FramelessWindowHint);
    //setAttribute(Qt::WA_TranslucentBackground,true);
    ui->setupUi(this);
}

TransWindow::~TransWindow()
{
    delete ui;
}

在不同的源代碼中,您會看到注釋掉的行,這是我嘗試過的不同內容.在大多數情況下,問題是,如果我取消注釋掉任何試圖設置Qt::FramlessWindowHint"的行,程序會正常運行,但當我單擊主用戶界面上的按鈕時永遠不會打開新窗口.

In the different source codes you'll see commented out lines which is the different things that I've tried. For the most part the problem is, if I un-comment out any of the lines that try to set the "Qt::FramlessWindowHint" the program runs normally but never opens a new window when I click the button on the main ui.

如果我取消注釋掉我設置Qt::WA_TranslucentBackground"的任何行,當在主用戶界面中按下按鈕時,新窗口將打開,但新窗口的背景是黑色的,而不是透明.

If I un-comment out any of the lines where I set the "Qt::WA_TranslucentBackground" the new window will open up when when the button is pressed in the main ui but the background of the new window is black, not transparent.

其他可能相關的信息:linux: ubunto 12.04qt 5.0.2(64 位)qt 創作者 2.7.1

Other info that may be pertinent: linux: ubunto 12.04 qt 5.0.2 (64-bit) qt creator 2.7.1

推薦答案

試試這個:

setWindowFlags(Qt::Widget | Qt::FramelessWindowHint);
setParent(0); // Create TopLevel-Widget
setAttribute(Qt::WA_NoSystemBackground, true);
setAttribute(Qt::WA_TranslucentBackground, true);  
setAttribute(Qt::WA_PaintOnScreen); // not needed in Qt 5.2 and up

這篇關于無框透明窗qt5的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 ()?環形?)
主站蜘蛛池模板: 亚洲午夜精品在线观看 | av在线免费网站 | 久久一| 超碰在线亚洲 | 亚洲成人av | 一区二区中文 | 亚洲欧美日韩精品久久亚洲区 | 91亚洲国产成人久久精品网站 | 亚洲美女网站 | 狠狠干狠狠操 | 91看片在线观看 | 99只有精品| 国产成人99久久亚洲综合精品 | 国产丝袜一区二区三区免费视频 | 欧美激情在线精品一区二区三区 | 日韩一区二区免费视频 | 久久国产美女视频 | 欧美一级淫片007 | 亚洲狠狠 | 国产成人精品一区二区三区网站观看 | 国产精品99久久久久久久久久久久 | 一区二区小视频 | 国产精品久久久久久久久免费软件 | 一级国产精品一级国产精品片 | 中文字幕日韩欧美一区二区三区 | 成年人在线观看视频 | 黄色精品视频网站 | 97精品久久 | 亚洲精品自拍视频 | 欧美一区二区三区在线看 | 天天躁日日躁性色aⅴ电影 免费在线观看成年人视频 国产欧美精品 | 日韩中文一区二区三区 | 91亚洲国产亚洲国产 | 高清一区二区三区 | 一区二区三区视频免费看 | 中文字幕视频在线看 | 日韩理论电影在线观看 | 国产精品99久久久久久久久久久久 | 国产精品久久久久久久免费大片 | 蜜臀网 | 国外成人在线视频 |