Posts: 1,006
Threads: 330
Joined: Mar 2007
Hi All,
I have been able to accomplish a lot with the examples and advice in QmGrid and Sqlite ( SQL Lite and QM) . Only problem is that on my monitors, the font and row heights are small. I was wondering if it was possible to format these a bit: Row Height, Font, Font Color, Cell Background Color. I am not interested in these being adjustable on the fly by the user, but, more simply, ahead of time, by the script...perhaps a Cell Background Color or specific Font depending on content of cell at time of QMGrid population. Maybe even an icon or bmp.
I know QMGrid is based on SysListView32 but I had trouble finding examples to reverse-engineer. I know that the Options --> Editor is based on this, but couldn't find it in the system folders.
Thanks for any advice!
Stuart
Posts: 12,066
Threads: 140
Joined: Dec 2002
Function dialog_qmgrid2
,case WM_INITDIALOG
,int hlv=id(3 hDlg)
,__Font- gfont.Create("" 20)
,SendMessage hlv WM_SETFONT gfont 0
,SendMessage hlv LVM_SETTEXTCOLOR 0 0xff0000
,SendMessage hlv LVM_SETTEXTBKCOLOR 0 0xe0ffff
,SendMessage hlv LVM_SETBKCOLOR 0 0xe0ffff
To set different colors for cells, use custom draw. Look in explorer style dialog sample. It is somewhere in forum. DEX_Dialog etc. Look for NM_CUSTOMDRAW in code.
Posts: 1,006
Threads: 330
Joined: Mar 2007
Which one is right?
Lithuanian (Lithuania) Achiu
Lithuanian (Lithuania) Dekoju
Lithuanian (Lithuania) [very much] Labai achiu
Lithuanian (Lithuania) Dekui
Lithuanian (Lithuania) Labai dekoju
Lithuanian (Lithuania) [very sincere] NuoĆĄirdziai dekoju
Stuart
Posts: 12,066
Threads: 140
Joined: Dec 2002
all almost right
Posts: 1,006
Threads: 330
Joined: Mar 2007
Hi Gintaras, Thanks again for help above.
Wondering if it is possible to have different font color per cell like in the options dialog.
Also, I was playing with adding icons to DlgGrid but it seems to only be able to add icons to cell in first column using SetRowType with an image list. Is it possible to set an icon in different cells.
Thanks so much either way, if possible or let me know if not,
S
Posts: 12,066
Threads: 140
Joined: Dec 2002
Function dialog_grid_cell_color_icon
\Dialog_Editor
DlgGrid g
__ImageList il
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 QM_Grid 0x56031041 0x0 0 0 224 114 "0x2,0,0,0,0x0[]A,,,[]B,,,"
;END DIALOG
;DIALOG EDITOR: "" 0x2030605 "*" "" "" ""
str controls = "3"
str qmg3x
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc v
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG goto gInit
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto gNotify
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
;_______________________
;gInit
g.Init(hDlg 3)
il.Load("$qm$\il_dlg.bmp")
g.SetImagelist(il)
SendMessage g LVM_SETEXTENDEDLISTVIEWSTYLE LVS_EX_SUBITEMIMAGES LVS_EX_SUBITEMIMAGES
str csv=
;A1,B1
;A2,B2
;A3,B3
g.FromCsv(csv ",")
ret
;_______________________
int row col
;gNotify
NMHDR* nh=+lParam
sel nh.idFrom
,case 3
,sel nh.code
,,case NM_CUSTOMDRAW goto gCustomDraw
,,case LVN_GETDISPINFOW goto gGetDispInfo
ret
;_______________________
;gCustomDraw
NMCUSTOMDRAW* cd=+lParam
NMLVCUSTOMDRAW* cd2=+lParam
int R ;;the return value
sel cd.dwDrawStage
,case CDDS_PREPAINT
,R=CDRF_NOTIFYITEMDRAW ;;notify to draw items
,
,case CDDS_ITEMPREPAINT ;;now draw item
,R=CDRF_NEWFONT|CDRF_NOTIFYSUBITEMDRAW ;;notify to draw subitems
,
,case CDDS_ITEMPREPAINT|CDDS_SUBITEM ;;now draw subitem
,row=cd.dwItemSpec; col=cd2.iSubItem
,if(row=1 and col=1)
,,cd2.clrText=0xff
,,cd2.clrTextBk=0xc0e0c0
ret DT_Ret(hDlg R)
;_______________________
;gGetDispInfo
NMLVDISPINFOW& di=+nh
LVITEMW& u=di.item
if u.mask&LVIF_IMAGE
,row=u.iItem; col=u.iSubItem
,if(row=1 and col=1)
,,u.iImage=6
,else u.iImage=I_IMAGENONE
ret
Posts: 1,006
Threads: 330
Joined: Mar 2007
Amazing! Thanks for taking time away from QM3! The NUM_CUSTOMDRAW, ITEMDRAW and PREPAINT, etc has been so difficult for me to try to implement. I have played around with it a couple of times in the past. Thanks again for making such a clear example for me and rest of forum/QM-world to learn from!
S
Posts: 1,006
Threads: 330
Joined: Mar 2007
Thanks again Gintaras. I have been trying and it works very well for setting up initial row/cell colors (text/background). But if I want to change
e.g. change row color depending on click or based on a separate trackbar item, I can't seem to make it work without multiplying all the rows, I want to color.
I think I need some way to clear all rows of formatting but can't figure this out.
if I try to loop through all rows and apply a 'default' background, it only works at startup but not on subsequent clicks.
I have put 'goto gCustomDraw' into items like case [NM_CLICK,NM_DBLCLK,NM_RCLICK], but it doesn't really work. Something maybe with the fact that it is 'prepaint"? Not sure what that means. I have tried to look at DEX example but same issue.
Thanks for any guidance.
S
Posts: 12,066
Threads: 140
Joined: Dec 2002
02-06-2019, 07:36 AM
(This post was last modified: 02-06-2019, 07:41 AM by Gintaras.)
Function dialog_grid_cell_color_icon2
DlgGrid g
__ImageList il.Load("$qm$\il_dlg.bmp")
str csv=
;A1,B1
;A2,B2
;A3,B3
;array for colors etc of all cells
type __Cell8256 textColor backColor iconIndex
ARRAY(__Cell8256) c.create(2 3) ;;2 columns, 3 rows
;set default colors etc
sub.SetDefautCellFormatForAll
sub.SetCellFormat(0 1 4 0 0 4)
sub.SetCellFormat(0 2 2|4 0 0xe0c0c0 8)
sub.SetCellFormat(1 1 1|2|4 0xff 0xc0e0c0 6)
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 QM_Grid 0x56031041 0x0 0 0 224 114 "0x2,0,0,0,0x0[]A,,,[]B,,,"
;4 Button 0x54032000 0x0 4 116 48 14 "Change"
;5 Button 0x54032000 0x0 56 116 48 14 "Clear"
;END DIALOG
;DIALOG EDITOR: "" 0x2040800 "*" "" "" ""
str controls = "3"
str qmg3x
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc v
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG goto gInit
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto gNotify
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 4 ;;Change
,sub.SetCellFormat(0 1 1 0x00aa00) ;;change text color
,sub.SetCellFormat(0 2 2|0x100 0 0xa0ffa0) ;;change background color, clear text color and icon
,sub.SetCellFormat(1 1 0x100) ;;clear all attributes
,sub.Redraw
,case 5 ;;Clear
,sub.SetDefautCellFormatForAll
ret 1
;_______________________
;gInit
g.Init(hDlg 3)
g.SetImagelist(il)
SendMessage g LVM_SETEXTENDEDLISTVIEWSTYLE LVS_EX_SUBITEMIMAGES LVS_EX_SUBITEMIMAGES
g.FromCsv(csv ",")
ret
;_______________________
int row col
;gNotify
NMHDR* nh=+lParam
sel nh.idFrom
,case 3
,sel nh.code
,,case NM_CUSTOMDRAW goto gCustomDraw
,,case LVN_GETDISPINFOW goto gGetDispInfo
ret
;_______________________
;gCustomDraw
NMCUSTOMDRAW* cd=+lParam
NMLVCUSTOMDRAW* cd2=+lParam
int R ;;the return value
sel cd.dwDrawStage
,case CDDS_PREPAINT
,R=CDRF_NOTIFYITEMDRAW ;;notify to draw items
,
,case CDDS_ITEMPREPAINT ;;now draw item
,R=CDRF_NEWFONT|CDRF_NOTIFYSUBITEMDRAW ;;notify to draw subitems
,
,case CDDS_ITEMPREPAINT|CDDS_SUBITEM ;;now draw subitem
,row=cd.dwItemSpec; col=cd2.iSubItem
,cd2.clrText=c[col row].textColor
,cd2.clrTextBk=c[col row].backColor
ret DT_Ret(hDlg R)
;_______________________
;gGetDispInfo
NMLVDISPINFOW& di=+nh
LVITEMW& u=di.item
if u.mask&LVIF_IMAGE
,row=u.iItem; col=u.iSubItem
,u.iImage=c[col row].iconIndex
ret
#sub SetDefautCellFormatForAll v
int i j
for(i 0 c.len)
,for(j 0 c.len(1))
,,c[j i].textColor=0
,,c[j i].backColor=0xffffff
,,c[j i].iconIndex=I_IMAGENONE
if(g) InvalidateRect g 0 1
#sub SetCellFormat v
function column row flags [textColor] [backColor] [iconIndex] ;;flags: 1 text, 2 back, 4 icon, 0x100 clear
__Cell8256& r=c[column row]
if(flags&0x100) r.textColor=0; r.backColor=0xffffff; r.iconIndex=I_IMAGENONE
if(flags&1) r.textColor=textColor
if(flags&2) r.backColor=backColor
if(flags&4) r.iconIndex=iconIndex
#sub Redraw v
InvalidateRect g 0 1
Posts: 1,006
Threads: 330
Joined: Mar 2007
unbelievable! Can't wait to workout and learn from what you have done here in such a short time.
It's already close to 4 am my time and I have to function tomorrow but I am attempted to work through the night just to explore this amazing code!
Thanks so much!,
S
|