我有一个带文本交互的QGraphicsTextitem,用户可以编辑当前文本并添加新文本。但我的新要求是增加选择轮廓宽度,并可由QSlider控制。是否可以增加QGraphicsTextItem的点选择宽度。 我想增加文本周围选择框的笔厚度或大小..
在图像中用虚线绑定文本。是否可以增加虚线笔的尺寸或厚度。
答案 0 :(得分:1)
这个问题很古老,但我会履行我的公民义务来尝试答案:
你必须做一些事情。
对您的paint
覆盖void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
QStyleOptionGraphicsItem opt(*option);
// Remove the selection style state, to prevent the dotted line from being drawn.
opt.state = QStyle::State_None;
// Draw your fill on the item rectangle (or as big as you require) before drawing the text
// This is where you can use your calculated values (as member variables) from what you did with the slider
painter->setPen(Qt::NoPen);
painter->setBrush(Qt::green);
painter->drawRect(whateverRectangle());
// Call the parent to do the actual text drawing
QGraphicsTextItem::paint(painter, &opt, widget);
// You can use these to decide when you draw
bool textEditingMode = (textInteractionFlags() & Qt::TextEditorInteraction);
bool isSelected = (option->state & QStyle::State_Selected);
// Draw your rectangle - can be different in selected mode or editing mode if you wish
if (option->state & (QStyle::State_Selected))
{
// You can change pen thickness for the selection outline if you like
painter->setPen(QPen(option->palette.windowText(), 0, Qt::DotLine));
painter->setBrush(Qt::magenta);
painter->drawRect(whateverRectangle());
}
}
方法,在其中删除默认选择样式,并绘制自己的
boundingRect
opaqueArea
,shape
和allprojects {
repositories {
//...
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "25.4.0"
}
}
}
}
}
功能,以说明您的尺寸增加。