QSpinBox箭头放置在外线编辑(css)

时间:2012-02-22 05:54:48

标签: css qt stylesheet qspinbox

image http://wiki.metrotek.spb.ru/mw/images/a/a9/Style-override.png

如何使用Qt CSS帮助?

我尝试使用

subcontrol-origin: margin;
position: absolute;

但没有成功。

感谢您的帮助

修改

感谢您的帮助,我的问题的最终CSS是:

QSpinBox#spin {
margin-left: 20px;  /* make room for the arrows */
margin-right: 20px;  /* make room for the arrows */
width: 20px;

border: 2 solid #515151;
background-color: #434343;
}

QSpinBox#spin::up-button  {
subcontrol-origin: margin;
subcontrol-position: center left;

width: 19px;
border-width: 1px;
}

QSpinBox#spin::up-arrow  {
image: url(:/res/images/up.png);

min-width: 19px;
min-height: 14px;
max-width: 19px;
max-height: 14px;
height: 19px;
width: 14px;
}

QSpinBox#spin::up-button:pressed  {
top: 1px;
right: 1px;
}

QSpinBox#spin::down-button  {
subcontrol-origin: margin;
subcontrol-position: center right;
width: 19px;
border-width: 1px;
}

QSpinBox#spin::down-arrow  {
image: url(:/res/images/down.png);

min-width: 19px;
min-height: 14px;
max-width: 19px;
max-height: 14px;
height: 19px;
width: 14px;
}

QSpinBox#spin::down-button:pressed  {
top: 1px;
left: 1px;
}

和额外的CSS像奖金:) 如果您想在右侧编辑之外设置“向上,向下”箭头的位置:

QSpinBox#spin {
margin-right: 40px;  /* make room for the arrows */
width: 20px;

border: 2 solid #515151;
background-color: #434343;
}

QSpinBox#spin::up-button  {
subcontrol-origin: margin;
subcontrol-position: center right;
position: relative;

left: -20px;   /*   shift position back*/
width: 19px;
border-width: 1px;
}

QSpinBox#spin::down-button  {
subcontrol-origin: margin;
subcontrol-position: center right;
width: 19px;
border-width: 1px;
}

1 个答案:

答案 0 :(得分:2)

您是否看过Qt样式表指南?他们有一个非常具体的例子来说明如何定位你的上下箭头:

here is the link

QSpinBox {
     padding-right: 15px; /* make room for the arrows */
     border-image: url(:/images/frame.png) 4;
     border-width: 3;
 }

 QSpinBox::up-button {
     subcontrol-origin: border;
     subcontrol-position: top right; /* position at the top right corner */

     width: 16px; /* 16 + 2*1px border-width = 15px padding + 3px parent border */
     border-image: url(:/images/spinup.png) 1;
     border-width: 1px;
 }

 QSpinBox::down-button {
     subcontrol-origin: border;
     subcontrol-position: bottom right; /* position at bottom right corner */

     width: 16px;
     border-image: url(:/images/spindown.png) 1;
     border-width: 1px;
     border-top-width: 0;
 }

只需调整子控制位置即可。并调整QSpinBox的填充,以便在左侧填充。