Change selection text color in QGraphicsTextItem



  • as the default behavior is , whenever you select text in qgraphicstextitem, it shows blue color rectangle and make selected text color white, i need original color to be there at the time of selection

    for ex. if i have a qgraphicstextitem text is yellow in color, then if i select some text , then blue color rectangle will come and text color should be in same .. yellow.



  • there are 2 solutions to it...
    First i can set QApplication.setPalette()
    and second is to set css in setHtml of qgraphicstextitem

    i need to go by second route....
    can anybody help me in doing so .... i need to change selected/ highlighted text color in textitem of xyz color and selected/highlighted backgound color to be in abc color ?????



  • We explicitly did not make the original yellow text yellow since it would be unreadable with a blue background.
    The palette also is designed to have a selected-text and selected-background color that are system-wide. This is designed as such by Windows and Mac and others.

    If you really want to keep the original color, this likely means you don't want to use a selection. Maybe you can paint a rectangle yourself?
    Also be ready for complaints about text being unreadable when you ignore 20 year old rules ;)



  • @Thomos

    boss what powerpoint does, it also has textitem , whenever u select some text in that textitem, it shows blus color rectangle, and keeps the selected text in original color, it doesnt change the color to hard code WHITE...

    i also want that functionality , i searched a lot, then i came to know that i achieve this by setting QApplication. setPalette () or by setting CSS in setHtml() of qgraphicstextitem...
    i tried some css selection color change in simple html file which i ran in mozzila , it works well , it gave what ever i set the selection text color , and selection backgound color

    well but same code doesnt work in setHtml() .

    @
    <html>
    <head>
    <style type="text/css">

    p{
    selection-color: #FFFF00;
    selection-background-color: #FF0000;
    }

    </style>

    </head>
    <p>
    nikhil is good boy
    </p>
    <body>
    </body>
    </html>
    @



  • @thomas

    in simple words, i want to change this selection background color and selection text color, well unreadability is the different thing.

    for solving unreadability i will choose some good colors.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.