zoukankan      html  css  js  c++  java
  • unix qt 与 windows qt的用法差异

    1. QT样式表设置背景色 background-color无效的原因

    QPushButton
     {
           background-color: red;
    }

    结果发现,按钮的背景色并没有被设置为红色!

    问题的原因,QT的帮助文档里讲了,比较难找,打开帮助文档,依次展开->style sheet->Qt Style Sheets Reference,找到表格中的QPushButton,如下图所示


    大体意思就是,要想使背景色生效,必须要设置一下某个border属性,border-color、border-width等等任何一个跟border相关的属性都行。因为pushbutton的原生边界把背景色给覆盖住了。

        accountLoginButton->setStyleSheet("background-color:transparent;border:none;");//设置QListWidget背景色为透明
        uniteLoginButton->setStyleSheet("background-color:transparent;border:none;");//设置QListWidget背景色为透明

    2. Qt窗体设置Qt::WA_TranslucentBackground为全黑的原因

    背景漆黑的部分其实就是透明的部分...大多是因为桌面没有设置成32色导致的

    你的桌面是32色的么?
    还有你安装了显卡驱动了么?
    背景漆黑的部分其实就是透明的部分...

    如果要想要半透明效果应该用setWindowOpacity,WA_TranslucentBackground是背景透明控件不透明的效果。

        //TODO,still has border
        //设置窗体透明
        if(operateSystem=="windows"){
            this->setAttribute(Qt::WA_TranslucentBackground, true);
        }else{
            this->setWindowOpacity(0.0);
    //        this->setAttribute(Qt::WA_TranslucentBackground, false);
    //        this->setStyleSheet("background-color:rgba(0, 0, 0, 0);border:none;");
        }

    ------解决方案--------------------
    setWindowOpacity(0.5);
    ------解决方案--------------------
    一般要把窗体设置为FramelessWindowHint属性,WA_TranslucentBackground才能生效。如果要想要半透明效果应该用setWindowOpacity,WA_TranslucentBackground是背景透明控件不透明的效果。

    在Qt中,设置窗体透明度的函数有:void   setWindowOpacity(qreal level)

    特性:
        透明度的有效范围从1.0(完全不透明)到0.0(完全透明的)。
        默认情况下,此属性的值是1.0。(也就是不透明状态)
        这个特性可以在嵌入式Linux、Mac OS X、Windows、和X11平台上使用。
        此功能不可用在Windows CE。
        还要注意,半透明的windows更新和调整明显慢于不透明的窗口。(透明窗体的刷新速度会变慢)

    qt在linux下设置widget透明的方法

    Qt参考文档
    Platform notes:
    X11: This feature relies on the use of an X server that supports ARGB visuals and a compositing window manager.
    Windows: The widget needs to have the Qt::FramelessWindowHintwindow flag set for the translucency to work.

    平台注意事项:
    X11(linux):此特性依赖于能提供支持ARGB视觉效果和复合式视窗管理的X服务的功能开启。
    Windows:此控件需要设置窗口标志Qt::FramelessWindowHint才能开启透明功能。

    在windows上设置widget属性
    setWindowFlags(Qt::FramelessWindowHint);
    setAttribute(Qt::WA_TranslucentBackground,true);
    可以实现透明功能,但是在linux上需要安装渲染工具compiz 方法如下:
    root用户下: yum install compiz
    运行:compiz --replace &

     3. linux qt QSystemTrayIcon不支持

    https://forum.qt.io/topic/54004/qsystemtrayicon-in-linux/7

         //TODO
         QSystemTrayIcon *trayicon = new QSystemTrayIcon();

    4. Linux QT

    QComboBox选择框被挡住原因

    5. 查看有没安装浏览器等软件

    windows下查看注册表即可

    linux下需要使用命令行

    在linux平台下,我们很容易想到用命令:ps -a | grep processName来对进程进行查找。进而想到用QProcess来执行这一个命令。

    然而遗憾的是,QProcess不提供对管道的支持,这里我们采用一个变通的方法:利用 sh 来执行上面的命令。

    代码如下:

    QProcess ps;

    connect(&ps,SIGNAL(readyReadStandardOutput()),this,SLOT(readProcessStandardOutput()));

    QStringList args;

    args<<"-c";

    args<<"ps | grep 'processName";

    ps.start("sh",args);

    readProcessStandardOutput()

    {

       ps.readAllStandardOutput()   // 得到sh -c "ps | grep 'processName‘“ 的输出结果,查看这个结果就可以得到这个结果是否在运行。

    }

    linux下如何查看某软件是否已安装

    因为linux安装软件的方式比较多,所以没有一个通用的办法能查到某些软件是否安装了。总结起来就是这样几类:

    1、rpm包安装的,可以用rpm -qa看到,如果要查找某软件包是否安装,用 rpm -qa | grep “软件或者包的名字”。

    1
    [root@hexuweb102 ~] rpm -qa | grep ruby

    2、以deb包安装的,可以用dpkg -l能看到。如果是查找指定软件包,用dpkg -l | grep “软件或者包的名字”;

    1
    [root@hexuweb102~]dpkg-l|grepruby

    3、yum方法安装的,可以用yum list installed查找,如果是查找指定包,命令后加 | grep “软件名或者包名”;

    1
    [root@hexuweb102 ~] yum list installed | grep ruby

    4、如果是以源码包自己编译安装的,例如.tar.gz或者tar.bz2形式的,这个只能看可执行文件是否存在了,

    上面两种方法都看不到这种源码形式安装的包。如果是以root用户安装的,可执行程序通常都在/sbin:/usr/bin目录下。

    说明:其中rpm yum 是Redhat系linux的软件包管理命令,dpkg是debian系列的软件包管理命令


    6. 打开程序

    windows下

    QProcess *p = new QProcess(this);

    p->startDetached(installerSuccessLaunchCmdLine, QStringList() << "/c" << systemLoginHomePage);

    linux下

    QProcess *p = new QProcess(this);
    p->startDetached("/opt/chromium.org/chromium/chromium-browser", QStringList() << systemLoginHomePage);

  • 相关阅读:
    Akka详细介绍
    列举spark所有算子
    command not found所有执行命令总是报找不到
    Spark启动报错|java.io.FileNotFoundException: File does not exist: hdfs://hadoop101:9000/directory
    斐波那契数列的优化
    ganglia之web界面介绍
    linux环境下载和安装scala
    windows清空电脑的DNS缓存
    win10安装mysql一直卡在最后一步进行不下去
    maven的依赖管理详细
  • 原文地址:https://www.cnblogs.com/xiang--liu/p/12981262.html
Copyright © 2011-2022 走看看