• 4647阅读
  • 1回复

[提问]QT程序窗口透明问题求助 [复制链接]

上一主题 下一主题
离线meguoe
 

只看楼主 正序阅读 楼主  发表于: 2014-08-11
公司用QT开发的程序界面,在服务器上运行,2003服务器和2008服务器在本地运行时一切正常,但是如果用远程桌面进入,程序就无法打开了。(可以看到进程已经启动,而且程序任务图标的右键也可以显示出来。)已经找到问题,【this->setAttribute(Qt::WA_TranslucentBackground, true); 】注释掉设置透明的代码或将他设置为false,远程就可以打开了,但是界面整体效果就不好看了。
把代码贴出来,大家看看有没有好的解决方法。


#include "shadow_widget.h"

ShadowWidget::ShadowWidget(QWidget *parent)
    : QWidget(parent)
{
    this->setWindowFlags(Qt::FramelessWindowHint | Qt::Window);
    this->setAttribute(Qt::WA_TranslucentBackground, true);
    this->setFocusPolicy(Qt::StrongFocus);

    mouse_press = false;
    QDesktopWidget *desktop_widget = QApplication::desktop();
    desktop_width = desktop_widget->availableGeometry().width();
    desktop_height = desktop_widget->availableGeometry().height();

    this->setMaximumSize(desktop_width, desktop_height);
}

ShadowWidget::~ShadowWidget()
{
    
}

void ShadowWidget::mousePressEvent(QMouseEvent *event)
{    
    if (event->button() == Qt::LeftButton && (QRect(5, 3, this->width()-10, this->height()-6)).contains(event->pos()))
    {
        mouse_press = true;
        press_point = event->pos();
    }
}

void ShadowWidget::mouseMoveEvent(QMouseEvent *event)
{
    if (mouse_press)
    {
        //判断鼠标是否移动至任务栏
        QPoint global_point = event->globalPos();
        if (global_point.y() >= desktop_height)
        {
            QCursor cursor = this->cursor();
            cursor.setPos(cursor.pos().x(), desktop_height-1);
        }
        QPoint move_point = global_point - press_point;
        int move_x = move_point.x();
        int move_y = move_point.y();
        int bottom = desktop_height-WINDOW_BORDER-5;

        if (move_y > bottom)
            move_y = bottom;

        move(move_x, move_y);    
    }
}

void ShadowWidget::mouseReleaseEvent(QMouseEvent *)
{
    mouse_press = false;
}

void ShadowWidget::paintEvent(QPaintEvent *event)
{
    QPixmap m_shadow(":/Images/window_shadow");
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing, true);

    QRect bottom(5, 136, 200, 7);
    QRect top(5, 0, 200, 3);
    QRect left(0, 3, 5, 133);
    QRect right(205, 3, 5, 133);
    QRect topRight(205, 0, 5, 3);
    QRect topLeft(0, 0, 5, 3);
    QRect bottomLeft(0, 136, 5, 7);
    QRect bottomRight(205, 136, 5, 7);

    QRect tBottom(5, this->height() - 7, this->width() - 10, 7);
    QRect tTop(5, 0, this->width() - 10, 3);
    QRect tLeft(0, 3, 5, this->height() - 10);
    QRect tRight(this->width() - 5, 3, 5, this->height() - 10);
    QRect tTopLeft(0, 0, 5, 3);
    QRect tTopRight(this->width() - 5, 0, 5, 3);
    QRect tBottomLeft(0, this->height() - 7, 5, 7);
    QRect tBottomRight(this->width() - 5, this->height() - 7, 5, 7);

    painter.drawPixmap(tBottom, m_shadow, bottom);
    painter.drawPixmap(tTop, m_shadow, top);
    painter.drawPixmap(tLeft, m_shadow, left);
    painter.drawPixmap(tRight, m_shadow, right);
    painter.drawPixmap(tTopRight, m_shadow, topRight);
    painter.drawPixmap(tTopLeft, m_shadow, topLeft);
    painter.drawPixmap(tBottomLeft, m_shadow, bottomLeft);
    painter.drawPixmap(tBottomRight, m_shadow, bottomRight);
}
离线abc100m

只看该作者 1楼 发表于: 2014-09-08
Qt 5.3.1已修复此BUG
快速回复
限100 字节
 
上一个 下一个