Results 1 to 6 of 6

Thread: How to remove the dotted rectangle of selection

  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to remove the dotted rectangle of selection

    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:



    Thanks.
    Giuseppe CalÃ

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to remove the dotted rectangle of selection

    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).
    J-P Nurmi

  3. #3
    Join Date
    Mar 2010
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to remove the dotted rectangle of selection

    Does this hold for QT 4.6? Meaning we cannot get rid of the dotted line in QT 4.6?

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to remove the dotted rectangle of selection

    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.

  5. #5
    Join Date
    Mar 2010
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to remove the dotted rectangle of selection

    Thanks for your prompt reply. I am using only setStyleSheet to decorate the QPushButton objects as follows:
    Qt Code:
    1. 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}"
    2. "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));}"
    3. "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));}");
    To copy to clipboard, switch view to plain text mode 
    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

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to remove the dotted rectangle of selection

    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.

  7. The following user says thank you to Lykurg for this useful post:

    moosa (19th April 2010)

Similar Threads

  1. How to paint a selection rectangle on a pixmap?
    By SkripT in forum Qt Programming
    Replies: 6
    Last Post: 8th January 2006, 19:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.