Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 6

Qt-interest Archive, March 2007
Re: changing combobox items color? (Qt422)


Message 1 in thread

I posted a question on this over a month ago with no response.  I've got a bug 
report into TT on this as it seems like a bug.  Setting the palette on the combo 
or the combo's view (i.e., the menu) has no effect.  I do have a workaround however.

Use the palette to set the colors of the combo box (not the menu), then, use the 
style sheet to set the color of the view (menu) - something like:

QPalette p = combo->palette()
// set the colors you want with the right color roles
...
// Substitute the colors you want here
QString styleSheet = "QAbstractItemView \
{ \
    background-color:   red; \
    color:                     white; \
    selection-background-color: white; \
    selection-color:                   red;
}";

QAbstractItemView *v = combo->view();
v->setStyleSheet(styleSheet);

HTH,
Susan

----- Original Message ----
From: eric placoly <billycobab@xxxxxxxxxxx>
To: veronique.lefrere@xxxxxx; qt-interest@xxxxxxxxxxxxx
Sent: Tuesday, March 27, 2007 6:35:23 AM
Subject: RE: changing combobox items color? (Qt422)

Hello,

  I do not know if it is the best way but i should use the model/view 
facilities. You define your model inheriting from QAbstractListModel and by 
reimplementing QAbstractListModel::data() method, you can return the role 
you need to manage item background and text color ( Qt::BackgroundRole and 
Qt::TextColorRole ). Then you attach your model to the combo box thanks to 
setModel() method.

  Regards,

  Eric.


>From: veronique.lefrere@xxxxxx
>To: qt-interest@xxxxxxxxxxxxx
>Subject: changing combobox items color? (Qt422)
>Date: Tue, 27 Mar 2007 10:03:04 +0200
>
>Hi,
>
>Is there a possibility using stylesheet to control combox items color? 
>(text color or background item color)?
>
>if someone can give me the best way to do this?...
>
>Thank you for any idea.
>
>Veronique.
>
>--
>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
>"unsubscribe" in the subject or the body.
>List archive and information: http://lists.trolltech.com/qt-interest/
>

_________________________________________________________________
Gagnez des pc Windows Vista avec Live.com http://www.image-addict.fr/

--
 [ signature omitted ] 

Message 2 in thread

susan@xxxxxxxxxxxx wrote:
> I posted a question on this over a month ago with no response.  I've got a bug 
> report into TT on this as it seems like a bug.  Setting the palette on the combo 
> or the combo's view (i.e., the menu) has no effect.  I do have a workaround however.
> 
> Use the palette to set the colors of the combo box (not the menu), then, use the 
> style sheet to set the color of the view (menu) - something like:
> 
> QPalette p = combo->palette()
> // set the colors you want with the right color roles
> ...
> // Substitute the colors you want here
> QString styleSheet = "QAbstractItemView \
> { \
>     background-color:   red; \
>     color:                     white; \
>     selection-background-color: white; \
>     selection-color:                   red;
> }";
> 
> QAbstractItemView *v = combo->view();
> v->setStyleSheet(styleSheet);
> 

You can do better. Set the following stylesheet on the combo box.

QComboBox {
    color: red;
    background-color: green;
     selection-color: magenta;
     selection-background-color: brown;
}

QComboBox QListView { /* the popup */
     color: blue;
     background-color: white;
     selection-color: gray;
     selection-background-color: cyan;
}

Girish

--
 [ signature omitted ] 

Message 3 in thread

Hi and thank you for all suggested solutions.

I tried Suzan proposed solution.
this work excepted that (I didn't give the info) I'm not sure that this 
will let me customizing colors for each item.
May be I have to look the suggestion of Eric (creating my own model to 
manage each item role).

the combobox list cameras.
color help user to distinguish user cameras (created by user) and 
default cameras (created by app).
so I may cutsomize each item (different text or background for user and 
app cameras)

the stylesheet solution change color for all items. is there a 
possibility with stylesheet to change for each item?


Veronique.


susan@xxxxxxxxxxxx a écrit :

>I posted a question on this over a month ago with no response.  I've got a bug 
>report into TT on this as it seems like a bug.  Setting the palette on the combo 
>or the combo's view (i.e., the menu) has no effect.  I do have a workaround however.
>
>Use the palette to set the colors of the combo box (not the menu), then, use the 
>style sheet to set the color of the view (menu) - something like:
>
>QPalette p = combo->palette()
>// set the colors you want with the right color roles
>...
>// Substitute the colors you want here
>QString styleSheet = "QAbstractItemView \
>{ \
>    background-color:   red; \
>    color:                     white; \
>    selection-background-color: white; \
>    selection-color:                   red;
>}";
>
>QAbstractItemView *v = combo->view();
>v->setStyleSheet(styleSheet);
>
>HTH,
>Susan
>
>----- Original Message ----
>From: eric placoly <billycobab@xxxxxxxxxxx>
>To: veronique.lefrere@xxxxxx; qt-interest@xxxxxxxxxxxxx
>Sent: Tuesday, March 27, 2007 6:35:23 AM
>Subject: RE: changing combobox items color? (Qt422)
>
>Hello,
>
>  I do not know if it is the best way but i should use the model/view 
>facilities. You define your model inheriting from QAbstractListModel and by 
>reimplementing QAbstractListModel::data() method, you can return the role 
>you need to manage item background and text color ( Qt::BackgroundRole and 
>Qt::TextColorRole ). Then you attach your model to the combo box thanks to 
>setModel() method.
>
>  Regards,
>
>  Eric.
>
>
>  
>
>>From: veronique.lefrere@xxxxxx
>>To: qt-interest@xxxxxxxxxxxxx
>>Subject: changing combobox items color? (Qt422)
>>Date: Tue, 27 Mar 2007 10:03:04 +0200
>>
>>Hi,
>>
>>Is there a possibility using stylesheet to control combox items color? 
>>(text color or background item color)?
>>
>>if someone can give me the best way to do this?...
>>
>>Thank you for any idea.
>>
>>Veronique.
>>
>>--
>>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
>>"unsubscribe" in the subject or the body.
>>List archive and information: http://lists.trolltech.com/qt-interest/
>>
>>    
>>
>
>_________________________________________________________________
>Gagnez des pc Windows Vista avec Live.com http://www.image-addict.fr/
>
>--
>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
>List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>
>
>--
>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
>List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>  
>


Message 4 in thread

I tried that and got some wierd color/behavior in cleanlooks style (i.e., (potential) checkboxes in all of the menu items.
 
The approach I used worked the best for me.
 

----- Original Message ----
From: Girish Ramakrishnan <girish@xxxxxxxxxxxxx>
To: susan@xxxxxxxxxxxx
Sent: Tuesday, March 27, 2007 11:20:59 AM
Subject: Re: changing combobox items color? (Qt422)

susan@xxxxxxxxxxxx wrote:
> I posted a question on this over a month ago with no response.  I've got a bug 
> report into TT on this as it seems like a bug.  Setting the palette on the combo 
> or the combo's view (i.e., the menu) has no effect.  I do have a workaround however.
> 
> Use the palette to set the colors of the combo box (not the menu), then, use the 
> style sheet to set the color of the view (menu) - something like:
> 
> QPalette p = combo->palette()
> // set the colors you want with the right color roles
> ...
> // Substitute the colors you want here
> QString styleSheet = "QAbstractItemView \
> { \
>     background-color:   red; \
>     color:                     white; \
>     selection-background-color: white; \
>     selection-color:                   red;
> }";
> 
> QAbstractItemView *v = combo->view();
> v->setStyleSheet(styleSheet);
> 

You can do better. Set the following stylesheet on the combo box.

QComboBox {
    color: red;
    background-color: green;
     selection-color: magenta;
     selection-background-color: brown;
}

QComboBox QListView { /* the popup */
     color: blue;
     background-color: white;
     selection-color: gray;
     selection-background-color: cyan;
}

Girish



--
 [ signature omitted ] 

Message 5 in thread

BTW - I still say this is a bug.  I want to be able to use a palette, not a stylesheet 
in my case.


----- Original Message ----
From: "susan@xxxxxxxxxxxx" <susan@xxxxxxxxxxxx>
To: qt-interest@xxxxxxxxxxxxx
Sent: Tuesday, March 27, 2007 11:59:09 AM
Subject: Re: changing combobox items color? (Qt422)

I tried that and got some wierd color/behavior in cleanlooks style (i.e., (potential) checkboxes in all of the menu items.
 
The approach I used worked the best for me.
 

----- Original Message ----
From: Girish Ramakrishnan <girish@xxxxxxxxxxxxx>
To: susan@xxxxxxxxxxxx
Sent: Tuesday, March 27, 2007 11:20:59 AM
Subject: Re: changing combobox items color? (Qt422)

susan@xxxxxxxxxxxx wrote:
> I posted a question on this over a month ago with no response.  I've got a bug 
> report into TT on this as it seems like a bug.  Setting the palette on the combo 
> or the combo's view (i.e., the menu) has no effect.  I do have a workaround however.
> 
> Use the palette to set the colors of the combo box (not the menu), then, use the 
> style sheet to set the color of the view (menu) - something like:
> 
> QPalette p = combo->palette()
> // set the colors you want with the right color roles
> ...
> // Substitute the colors you want here
> QString styleSheet = "QAbstractItemView \
> { \
>     background-color:   red; \
>     color:                     white; \
>     selection-background-color: white; \
>     selection-color:                   red;
> }";
> 
> QAbstractItemView *v = combo->view();
> v->setStyleSheet(styleSheet);
> 

You can do better. Set the following stylesheet on the combo box.

QComboBox {
    color: red;
    background-color: green;
     selection-color: magenta;
     selection-background-color: brown;
}

QComboBox QListView { /* the popup */
     color: blue;
     background-color: white;
     selection-color: gray;
     selection-background-color: cyan;
}

Girish






--
 [ signature omitted ]