QSpinBox 箭头放置在行编辑之外(css)
如何使用 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;
}
(source: metrotek.spb.ru)
How to do it with Qt CSS help ?
I have try to use
subcontrol-origin: margin;
position: absolute;
but no success.
Thank for any help
Edit
Thank you for help and final CSS for my problem is:
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;
}
and additional CSS like a bonus :)
If you like to setup position for "up,down" arrows outside the edit at the right side only:
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您看过 Qt 样式表指南吗?他们有一个关于如何定位向上和向下箭头的非常具体的示例:
这里是链接
只需调整子控制位置即可。并调整 QSpinBox 的填充,使其左侧也有填充。
Have you taken a look at the Qt Stylesheet guide? They have a really specific example of how to position your up and down arrows:
here is the link
Just adjust the subcontrol-position. And also adjust the padding for the QSpinBox to give it padding on the left as well.