Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
QSlider(Qt)的自定义图形_Qt_Slider_Custom Draw - Fatal编程技术网

QSlider(Qt)的自定义图形

QSlider(Qt)的自定义图形,qt,slider,custom-draw,Qt,Slider,Custom Draw,我想在QSlider上截取Qpaint事件并绘制它。但我找不到这东西的几何细节。我可以知道整个小部件的rect(),但是如何知道小部件矩形中第一个记号或最后一个记号的位置呢?(在跟踪通道的左侧和右侧有一个边距)。还是“手柄”的矩形?您是否希望舒尔重新实施绘画活动? 也许编写一份自定义样式表就足够了? 下面是doks的qslider示例: QSlider::groove:horizontal { border: 1px solid #999999; height: 8px;

我想在QSlider上截取Qpaint事件并绘制它。但我找不到这东西的几何细节。我可以知道整个小部件的rect(),但是如何知道小部件矩形中第一个记号或最后一个记号的位置呢?(在跟踪通道的左侧和右侧有一个边距)。还是“手柄”的矩形?

您是否希望舒尔重新实施绘画活动?
也许编写一份自定义样式表就足够了?
下面是doks的qslider示例:

 QSlider::groove:horizontal {
     border: 1px solid #999999;
     height: 8px; /* the groove expands to the size of the slider by default. by giving it a height, it has a fixed size */
     background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #B1B1B1, stop:1 #c4c4c4);
     margin: 2px 0;
 }

 QSlider::handle:horizontal {
     background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #b4b4b4, stop:1 #8f8f8f);
     border: 1px solid #5c5c5c;
     width: 18px;
     margin: -2px 0; /* handle is placed by default on the contents rect of the groove. Expand outside the groove */
     border-radius: 3px;
 }

您是否考虑过改用setStyleSheet?
如果你真的想自己画,你可以看看它是如何在Qt源代码中完成的:Qt/src/gui/widgets/qslider.cpp

谢谢回复中的提示。经过一些调查,这似乎奏效了。对于对某人有用的情况:

QStyleOptionSlider opt;
slider->initStyleOption(&opt);

QStyle *styl=style();
Rect rectHandle=styl->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, NULL);
Rect rectGroove=styl->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, NULL);

int avl=styl->pixelMetric(QStyle::PM_SliderSpaceAvailable, &opt, this); // width in an horizontal slider of the groove (width of widget - margins)

谢谢,事实上,我更容易截取QPaint,另外,我还想用数字方式绘制它,当其他值更改时,重新绘制背景(上下文是颜色定义HSL,每个滑块根据其他值绘制可用的色域),感谢源上的提示,从那里和一些测试,我可以找到所有我需要的。