HBQT, UI, QListWidget and setStyleSheet

804 views
Skip to first unread message

Zoran Sibinovic

unread,
Feb 4, 2015, 7:01:29 PM2/4/15
to qtcon...@googlegroups.com
Hi Pritpal,

Since the colors of selected or not selected items in UI environment are almost the same, and almost unvisible when the list is unfocused,
I have tried for a while to change the color for the selected items to be more stronger and to remain after unfocusing the list to another object,but without success.
Any stylesheet combination results with no effect, or, rarely, with a mess in colors when select/unselect the items.

Using windows 7 aero, sometimes the color of the selected items become light blu as the theme, unfocusing they go almost unvisible and somtimes there is no difference betwwen the selected and the not selected items. So Im never sure if the item is selected,not selected or just focused.

Lot of setstylesheet examples about QListWidgets color referencing on the net does nothing in this case so,
it is this possible to change the action color sheme of a list in a QListWidget object created in UI and called by HBQT? 

Thanks
Zoran

Zoran Sibinovic

unread,
Feb 5, 2015, 5:00:04 AM2/5/15
to qtcon...@googlegroups.com
Hi,

I also tried to: 

***
recreate the listwidget12 in the UI

***
   FOR i=1 TO LEN(aParts) ; oDlg:listWidget12:addItem( aParts[i] ) ; NEXT    

  oDlg:listWidget12:setStyleSheet( "QListWidget::item:selected { background-color: red }" )

****
FOR i=1 TO LEN(aParts2) 
       qItm := QListWidgetItem()
       qItm:setText( aParts3[i] )
       oDlg:listWidget12:addItem( qItm)
NEXT          
oDlg:listWidget13:setStyleSheet( "QListWidget::item:selected { background-color: red }" )

where aParts is an array of text items

replaced QListView instead QListWidget, and much more combination
but canot change the color if the item when selected. It is always white

any idea?

Thanks
Zoran

Francesco Perillo

unread,
Feb 5, 2015, 5:02:21 AM2/5/15
to qtcontribs
Instead of QSS, try to use QPalette to set proper color to the widget. Well, actually I don't know if it is possible to style that part but you can try. And you can also look at Qt code to know which color it uses (from where it takes the color to use)

--
You received this message because you are subscribed to the Google Groups "QtContribs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qtcontribs+...@googlegroups.com.
To post to this group, send email to qtcon...@googlegroups.com.
Visit this group at http://groups.google.com/group/qtcontribs.
For more options, visit https://groups.google.com/d/optout.

Zoran Sibinovic

unread,
Feb 5, 2015, 6:54:13 AM2/5/15
to qtcon...@googlegroups.com
Hi Francesco,

I already think of it, just not tried yet as last chance.
Intersting the listwidget created by code, not in UI, colored the selected items as the OS did for its. 

I will try it in the next days and let know.

Thanks
Zoran

Zoran Sibinovic

unread,
Feb 5, 2015, 7:43:19 AM2/5/15
to qtcon...@googlegroups.com
... the effect can be viewed in all the test apps with an listwidget in the UI as composite.exe
The selection remain of the same color as the background.


Zoran

Zoran Sibinovic

unread,
Feb 5, 2015, 8:48:35 AM2/5/15
to qtcon...@googlegroups.com
Hi,
I tried also the use of palette, made a listview object instrad the listwidget and directly setting the palette and the other color/colors options in the qt designer.

In all cases the Highlight and Higlightedtext color and bold properties never displays.
I can change the font color, the bacground, the alternatingrowscolor and all what I found with a prefix/sufix - color, bat the 2 above not
I tried to put in the designer some list items and set their color properties.
On compiling time some !@$~$~%$ errors shows... 

For now, I set a darker color for the backgroud so the selection, in white, go a little foreground.
In any case it's not a solution.

Zoran

Pritpal Bedi

unread,
Feb 5, 2015, 4:53:55 PM2/5/15
to qtcon...@googlegroups.com
Hi Zoran
As a rule o thumb, per my experience, applying CSS on QListWidget never works satisfactorily.

You need the approach below to achieve whatever you want.
First remove any stylesheet applied to QListWidget().



STATIC myLastClickedItem 


oListWidget := QListWidget()

WITH OBJECT oItem := QListWidgetItem()
   :setText( 0, "My First Prompt" )
   :setBackground( 0, QBrush( QColor( Qt_white ) )
   :setForeground( 0, QBrush( QColor( Qt_black ) )
   oListWidget:addItem( oItem )
ENDWITH

oListWidget:connect( ":​itemClicked(QListWidgetItem*)", {|oItem| oItem:setBackground( QBrush( QColor( Qt_blue ) ) ) } )

or better

oListWidget:connect( ":​itemClicked(QListWidgetItem*)", {|oItem| ReLayMyWidget( oListWidget, oItem ) } )


FUNCTION ReLayMyWidget( oListWidget, oItem )
      
   IF HB_ISOBJECT( oMyLastClickedItem )
      oMyLastClickedItem:setBackground( QBrush( QColor( Qt_white ) ) )
   ENDIF 
   oMyLastClickedItem := NIL 
   oMyLastClickedItem := oItem 
   oMyLastClickedItem:setBackground( QBrush( QColor( Qt_blue ) ) )

   RETURN NIL



Hope you get the point.
Note that if you have applied any stylesheet onto oListWidget, setBack/ForeGround() methods will not work.



Pritpal Bedi
a student of software analysis & concepts

Zoran Sibinovic

unread,
Feb 6, 2015, 8:46:05 AM2/6/15
to qtcon...@googlegroups.com
Hi Pritpal,

the things are ok if you use QListWidget() in the app code.
In this case the extended code you wrote is not needed, because the problem don't shows by using this way of listwidget creation, only in an UI environment.

Also oListWidget:connect( ":​itemClicked(QListWidgetItem*)"... without ":" in the message as oListWidget:connect( "​itemClicked(QListWidgetItem*)"

Wen used the :connect, in any combination of you example, happends that when we click the item, the item change the background color, but after then, when we release the
mouse shows up the automated solid "white" selection "button" when we select something to overriode our background and color. 
After we click again on it nothing happends till we release the mouse and than shows up the color we defined for the unselected item. I have played with the blue and yellow to get this order of events.

So we switch the background color but not the background color of the selected item "button" (its not a really button, but something solid on top).

Anyway seems that the problem is not in the code itself, but how much Qt,UI and OS colors and display system cooperates.

Since lot of my clients uses XP, no one complains on this problem, thing that made me think about what they see when running the app so, 
if you use an UI on Windows 7 pro or ultimate, you will get my problem in the selecting of items (selection color is white as the background), no matter if is Qlistview or Qlistwidget in question, but
if you switch the theme to Windows 7 clasic or you have the Windows 7 starter edition, the right colors in the selection displays. (blue).
Tried to find and change in the registry this color of "something" to solid, but not found.

So the Aero make the mess when used UI. On the net I found also, not sure if still, that Qt still keep for the UI the Windows Vista style for the windows environment, thing reported time ago.
Someone reports that changing the themes from Aero to something others, from the net, solved this problem.

Every Qlistwiew, Qlistwidget tat are created in UI in \tests had the same problem under Aero.

Not know for the other OSes, somebody says to have problems on some version of Linux too.

Zoran 


Zoran Sibinovic

unread,
Feb 6, 2015, 8:54:31 AM2/6/15
to qtcon...@googlegroups.com
... just only thanks at your source HBQT code that let us to directly create the dialogs and the widgets without using the UI 
it is possible to see the list selections also in Aero style. (transparent light blue selection color).

:)

Zoran 

Zoran Sibinovic

unread,
Feb 7, 2015, 5:57:55 PM2/7/15
to qtcon...@googlegroups.com
Hi to all,

this is a notice of what I tried and found about single or better, multipleselection, listwidget-s and listview-s used via hbqtui_:

1. Windows XP and XP with unchecked - "Use visual styles on windows and buttons" in widows "Performance options""
      - all selections and unselections are displayed with appropriate colors: blue and white

2. Windows 7 and with Aero or Basic theme 
      - all selections and unselections are displayed with the white color.  The selected items instead to be filled with a color, have only a rectangle border

3. Windows 7 with Classic theme or by unchecking the - "Use visual styles on windows and buttons" in widows "Performance options"
     - all selections and unselections are displayed with appropriate colors: blue and white

Now, how make it work on  Windows 7 and with Aero or Basic theme
By altering the Pritpals suggested code when filling the listwidget ther are 2 ways:


oDlg:listwidget13:setFocusPolicy( Qt_NoFocus )  // needed line that can be defined in Qt designer too and that permitt us to change the colors, without, nothing happends 

FOR i=1 TO LEN(aParts3)  // aPart3 is an array of text items
       oItem := QListWidgetItem()
       oItem:setText( aParts3[i] )
       oDlg:listWidget13:addItem( oItem )
  
 1.   oDlg:listwidget13:connect( "itemClicked(QListWidgetItem*)", {|oItem| oItem:setBackground(QBrush(QColor(IF(oItem:isSelected(),Qt_darkCyan ,Qt_white)))),oDlg:listWidget13:show() })   

      NEXT
  
 2.  oDlg:listwidget13:connect( "itemClicked(QListWidgetItem*)", {|| oDlg:listwidget13:currentItem():setBackground(QBrush(QColor(IF(oDlg:listwidget13:currentItem():isSelected(),Qt_darkCyan ,Qt_white)))),oDlg:listWidget13:show() })    


We achieve the switching o the 2 colors and the selection is now of another color instead of be white. 
There are 2 consequence of this:
   1. The selected buttons are no 3D like
   2. XP with unchecked - "Use visual styles on windows and buttons" in widows "Performance options""
      and Window 7 Classic users will see the selection as gray. No colors will be changed. That's because we turn of the focus policy. Now XP have its rules  

So it is getting really difficult to make happy everyone.

By using qpalette(), setstylesheet() or else, under UI, we can't customize the selection rectangle as in common circumstances, because the Aero won't let, in any manner, alter some visual defaults.

I found a good number od articles about this Qt problem with Aero, the problem extends also on Windows 8 and to other UI objects, but no some final answer, just suggestions to try this or try that.  

The interesting thing is that if we not use the UI, but we create the whole dialog with the elements by code in the prg, then the used visual style for the elements is the same as windows 7.
I dont know with what Qt designer saves the UI or how act hbqtui_ when reading it and generates the code, but maybe there is something that is missing in the formulation of listwigets and listviews.
This because the comboboxes in the UI through hbqtui_ , when we scrool the items, are of a right blue color, but the lists in listwidget and listview are not. 

At this moment I will move-back to the classic dialog creation for all my dialogs that uses listview and listwidget and wait till something shows up.

Zoran

Zoran Sibinovic

unread,
Feb 8, 2015, 4:13:59 AM2/8/15
to qtcon...@googlegroups.com
Hi to all,

FOUND THE CLUE!

After loaded the UI through hbqtui_  I added 2 QGet-s

 @ 0,0 QSAY "Date from " QGET dat1
 @ 1,0 QSAY "Datte to " QGET dat2 

You can misc a UI with gets like above but be careful to NOT FOCUS THEM AS FIRST when the initial display occurs.

If you make misc of objects like I did above and if you don't :setfocus() to some other object to be focused first, you will face the problem I've got.
After changed the initial focus to any other object, even a label (ex. label11:setfocus()), the listwidget palette colors go fine, according the native windows palette and styles, even Aero.
Now, If we had used :setfocus() like I said above, at some moment, enter in the gets and fill them and then go to some other object, the listwidgets doesn't go messy, they remain and continue to work as they have.

Seems that If we use this type of gets under a dialog that countain also listwidgets and are the first in line to be focused at the dialog apparence,
the dialog get some palettre/stylesheet or else that not allow the listwidgets to functioning in a correct way and also deny it's modification.

Zoran
Reply all
Reply to author
Forward
0 new messages