PDA

View Full Version : Dashed frame around QGraphicsTextItem



minimoog
20th November 2009, 03:41
I have a QGraphisTextItem with Qt::TextBrowserInteraction flag enabled. But when I select text (or any part of the text) there is dashed frame around whole text.

Does anybody knows how to remove the dashed frame?

Thanks in advance,
Toni

kichi
20th November 2009, 06:32
Qt::TextBrowserInteraction is not a flag for graphics item.

Perhaps, you should specify QGraphicsItem::GraphicsItemFlag or QGraphicsItem::GraphicsItemFlags, as follows.

textItem->setFlag(QGraphicsItem::ItemIsMovable, true); // item support interactive movement.
textItem->setFlag(QGraphicsItem::ItemIsSelectable, false); // if flag is true, item supports selection.

about QGraphicsItem::ItemIsSelectable flag, Qt Reference says

The item supports selection. Enabling this feature will enable setSelected() to
toggle selection for the item. It will also let the item be selected automatically as a
result of calling QGraphicsScene::setSelectionArea(), by clicking on an item, or by
using rubber band selection in QGraphicsView.

I'm sorry in poor English.

Lykurg
20th November 2009, 07:58
I have missed that question! It was several times asked here. Simply remove the QStyle::State_Selected option in the paint method of your item!

minimoog
20th November 2009, 15:11
Something like:


void StatusTextItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
{
QStyleOptionGraphicsItem *o = const_cast<QStyleOptionGraphicsItem*>(option);
o->state &= ~QStyle::State_Selected;
QGraphicsTextItem::paint(painter, o, widget);
}

It doesn't work, at least on Qt 4.6 RC1. I have not tested with Qt 4.5.3. I don't know if it's bug.

minimoog
20th November 2009, 15:17
Something like:


void StatusTextItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
{
QStyleOptionGraphicsItem *o = const_cast<QStyleOptionGraphicsItem*>(option);
o->state &= ~QStyle::State_Selected;
QGraphicsTextItem::paint(painter, o, widget);
}

It doesn't work, at least on Qt 4.6 RC1. I have not tested with Qt 4.5.3. I don't know if it's bug.

minimoog
20th November 2009, 16:02
Something like:


void StatusTextItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
{
QStyleOptionGraphicsItem *o = const_cast<QStyleOptionGraphicsItem*>(option);
o->state &= ~QStyle::State_Selected;
QGraphicsTextItem::paint(painter, o, widget);
}

It doesn't work, at least on Qt 4.6 RC1. I have not tested with Qt 4.5.3. I don't know if it's bug.

Lykurg
20th November 2009, 16:38
Ehm, for your case it's QStyle::State_HasFocus :cool:

minimoog
20th November 2009, 19:18
Ehm, for your case it's QStyle::State_HasFocus :cool:
Both: State_Selected and State_HasFocus. I have looked into the Qt 4.6 source code ;)

Problem fixed.