找回密码
 立即注册
收起左侧

QT界面边框透明问题。

1
回复
7785
查看
[复制链接]

尚未签到

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


#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:eftButton && (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);
}

最佳答案

查看完整内容

可能是远程桌面的窗口管理器为了保证性能,牺牲了显示的效果 毕竟你运行的是服务器版,自然不会考虑有多好看
回复

使用道具 举报

尚未签到

2014-8-18 09:10:33 显示全部楼层
可能是远程桌面的窗口管理器为了保证性能,牺牲了显示的效果

毕竟你运行的是服务器版,自然不会考虑有多好看
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了