PDA

View Full Version : How to remove the dotted rectangle of selection



jiveaxe
9th November 2007, 19:32
Since I am using different textures for distinguish normal state and selected state is it possible hide the rectangle bounding the selected item/widget?

Here what i mean:

http://img220.imageshack.us/img220/4600/forumhv6.th.jpg (http://img220.imageshack.us/my.php?image=forumhv6.jpg)

Thanks.

jpn
9th November 2007, 20:17
I think you got me now. :) I'm afraid you cannot alter appearance of focus rect with style sheets. In case you cannot use setFocusPolicy(Qt::NoFocus) (which leads to no keyboard input) you will have to rely on reimplemented QStyle::drawPrimitive(QStyle::PE_FrameFocusRect).

moosa
18th April 2010, 14:14
Does this hold for QT 4.6? Meaning we cannot get rid of the dotted line in QT 4.6?

Lykurg
18th April 2010, 14:59
You can, and the forum is full of post related to that issue! Use you own delegate, reimplement the paint method and alter option (QStyleOptionViewItem) by removing the desired state, e.g. QStyle::State_HasFocus.

moosa
18th April 2010, 22:31
Thanks for your prompt reply. I am using only setStyleSheet to decorate the QPushButton objects as follows:


setStyleSheet("QPushButton {background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(255, 255, 255, 255), stop:0.5 rgba(180, 180, 180, 255), stop:0.51 rgba(100, 100, 100, 255), stop:1 rgba(160, 160, 160, 255)); border-radius: 6px;padding: 2px; font: bold}"
"QPushButton::hover {background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(200, 255, 200, 255), stop:0.5 rgba(141, 180, 141, 255), stop:0.51 rgba(78, 100, 78, 255), stop:1 rgba(125, 160, 125, 255));}"
"QPushButton::pressed{background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(125, 160, 125, 255), stop:0.5 rgba(78, 100, 78, 255), stop:0.51 rgba(141, 180, 141, 255), stop:1 rgba(200, 255, 200, 255));}");

I just need to drop the dotted line when push button widget is selected. Is there a clean way I can use? If you can supply a tiny sample code or a short explanation it would be great.
Thanks in advance

Lykurg
18th April 2010, 23:00
As far as I know, there is no way to avoid that dotted rect using style sheets. You have to subclass your button and overwrite the paint event and do the drawing yourself. Use QStylePainter::drawPrimitive() with the right parameters.