QT - CSS:装饰的焦点 [英] QT - CSS: decoration on focus

查看:221
本文介绍了QT - CSS:装饰的焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我遇到这个问题:我有一个QPushButton,当它是一个在焦点它有一个矩形,它,我想删除。这里有一些屏幕截图:



正常按钮:





Focused按钮:





我试过添加某些内容(backgroundcolor,text-decoration等)

  QPushButton:focus 



有些提示?



这里是QPushButton css代码:

  QPushButton 
{
color :#b1b1b1;
background-color:QLinearGradient(x1:0,y1:0,x2:0,y2:1,stop:0#565656,stop:0.1#525252,stop:0.5#4e4e4e,stop:0.9#4a4a4a, stop:1#464646);
border-width:1px;
border-color:#1e1e1e;
border-style:solid;
border-radius:6;
padding:3px;
font-size:12px;
padding-left:5px;
padding-right:5px;
}

QPushButton:pressed
{
background-color:QLinearGradient(x1:0,y1:0,x2:0,y2:1,stop:0 #2d2d2d,stop:0.1#2b2b2b,stop:0.5#292929,stop:0.9#282828,stop:1#252525);
}

QPushButton:hover
{
border:2px solid QLinearGradient(x1:0,y1:0,x2:0,y2:1,stop:0 #ffa02f,stop:1#d7801a);
}

QPushButton:focus {
/ * background-color:red; * /
}

ps。我在Ubuntu 12.04,与Qt 4.8和我使用这个奇妙的css: http:// www .yasinuludag.com / darkorange.stylesheet

解决方案

突出显示的矩形可能是 QStyle :: PE_FrameFocusRect 样式。摆脱它的唯一方法是通过实现自定义风格。幸运的是,Qt提供了一种方法来实现一个代理,在一般情况下使用另一种风格。对于您要实现的焦点矩形:

  class Style_tweaks:public QProxyStyle 
{
public:

void drawPrimitive(PrimitiveElement element,const QStyleOption * option,
QPainter * painter,const QWidget * widget)const
{
/ *不绘制焦点矩形允许现代样式* /
if(element == QStyle :: PE_FrameFocusRect)
return;

QProxyStyle :: drawPrimitive(element,option,painter,widget);
}
};

qApp-> setStyle(new Style_tweaks);


I'm experimenting a bit with CSS for making a cool user interface for my QT application.

I have this problem: I have a QPushButton and when it is on focus it has a rectangle on it that I want to remove. Here some screen-shot:

Normal button:

Focused button:

I have tried to add something (backgroundcolor, text-decoration, etc)

QPushButton:focus

but it keeps on highlighting..

Some hints?

here is the QPushButton css code:

QPushButton
{
    color: #b1b1b1;
    background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #565656, stop: 0.1 #525252, stop: 0.5 #4e4e4e, stop: 0.9 #4a4a4a, stop: 1 #464646);
    border-width: 1px;
    border-color: #1e1e1e;
    border-style: solid;
    border-radius: 6;
    padding: 3px;
    font-size: 12px;
    padding-left: 5px;
    padding-right: 5px;
}

QPushButton:pressed
{
    background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #2d2d2d, stop: 0.1 #2b2b2b, stop: 0.5 #292929, stop: 0.9 #282828, stop: 1 #252525);
}

QPushButton:hover
{
    border: 2px solid QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #ffa02f, stop: 1 #d7801a);
}

QPushButton:focus {
    /*background-color: red;*/
}

ps. I'm on Ubuntu 12.04,with Qt 4.8 and I'm using this wonderfull css: http://www.yasinuludag.com/darkorange.stylesheet

解决方案

The highlighted rectangle may be the QStyle::PE_FrameFocusRect styling. The only way to get rid of it is by implementing a custom style. Fortunately, Qt provides a way to implement just a proxy, which uses another style in the general case. For the focus rectangle you'd implement:

class Style_tweaks : public QProxyStyle
{
    public:

        void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
                           QPainter *painter, const QWidget *widget) const
        {
            /* do not draw focus rectangles - this permits modern styling */
            if (element == QStyle::PE_FrameFocusRect)
                return;

            QProxyStyle::drawPrimitive(element, option, painter, widget);
        }
};

qApp->setStyle(new Style_tweaks);

这篇关于QT - CSS:装饰的焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆