I want to change item's height and width according to a slider, but as far as I know, there's no measureitem method as CListBox. How can I fix this?
Thank you!
All items in CListCtrl have to have the same size. I believe you can use OnMeasureItem in the container that holds the CListCtrl, but it won't be called for each item, but only once for the entire control.
The workaround is to attach an image list to the CListCtrl. The rows will then take on a height based on the height of the image list.
Related
First of all I am apologizing for my English in advance. I am trying to display a custom widget in a QListWidget, but when more than one row is added, they are displayed on the same spot.
(source: minespeed200.de)
Settings of the QListWidget
alternateingRowColors:true
movement:Static
isWrapping:false
resizeMode:adjust
layoutMode:singePass
spacing:1
viewMode:listMode
i've already tried all of the possible settings for this values. if there is another importent one i've missed (i am fairly new to Qt) please tell me. Also the row colors seem to overlap too (the picture of my application below has 2 rows added), what tells me, that not only the widget's but the row's are overlapping each other entirely.
(source: minespeed200.de)
(source: minespeed200.de)
I am adding the rows with this code:
item=new QListWidgetItem();
QSize size(this->width(),this->height());
item->setSizeHint(size);
list->addItem(item);
list->setItemWidget(item,this);
Inside of the constructor of my custom widget class.
The issue was that i left the gridSize of my QListWidget at it's default value and the y component had to be set to the height of my widget i was displaying.
Adding:
list->setGridSize(QSize(0,this->sizeHint().height()));
fixed it.
I think you need this method.
list->QListWidget::setFlow(QListWidget::LeftToRight)
check here: https://doc.qt.io/archives/qt-4.8/qlistview.html#flow-prop
Thanks coming!!
i want to adjust the item's height.look like this one:
but actually it is :
and i find 3 way to adjust the item height:
(1). add the picture but text is not in center.
m_ImageListCList.Create(16,36/*Here*/,ILC_COLOR24|ILC_MASK,$Cnt ,$Cnt);
m_ImageListCList.Add(&Bitmap2, RGB(192, 192, 192));
m_listSchedule.SetImageList(&m_ImageListCList, LVSIL_SMALL);
(2). edit the Font size , it's not pretty
(3). and i want to overwrite the DrawItem() MeasureItem() function of it.
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
afx_msg void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
ON_WM_MEASUREITEM_REFLECT()
ON_WM_DRAWITEM()
but MeasureItem() is work, DrawItem() couldn't called.
and then i find this context
MSDN Knowledge Base Q131788:
The LVS_OWNERDRAWFIXED style is only compatible with the LVS_REPORT style. You cannot have an owner drawn ListView with the LVS_ICON, LVS_SMALLICON or LVS_LIST style.
Now , i don't have better idea ... thanks a lot about your help!!
When MeasureItem works you can size your items, but did you try NM_CUSTOMDRAW. AFAIK it should work to.
If you only need to display an icon and some text and want to pick and select data, wouldn't a list box be sufficient?
Use a classic ListBox and some Ownerdraw mechansim.
I need to set background CListBox background.
I can't find solution for set different colors for each item.
How can I do that?
To get different colors for each item you have to owner-draw the list box. That means you must paint each item yourself. See the CTRLTEST sample in MSDN.
I currently have NM_CUSTOMDRAW message calling a function to color the rows of a listctrl in report mode. I can detect when a row is selected and color it myself, but this method doesn't get called for the cell that is selected, so I can't color that cell. So my question is 1) is there a way to have windows call my custom draw method for every cell whether it is selected or not? 2) If not what is the easiest way to make a selection span entire row.
Thanks,
CP
I found the answer, and Microsoft made it easier than I guess it used to be.
m_ListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT);
See:
https://learn.microsoft.com/en-gb/windows/win32/controls/extended-list-view-styles?redirectedfrom=MSDN
LVS_EX_FULLROWSELECT
When an item is selected, the item and all its subitems are highlighted. This style is available only in conjunction with the LVS_REPORT style.
I have a listwidget with items which have icons. When the item is selected both the text and the icon are highlighted. My problem is that when the icon is highlighted it just goes entirely black because I'm using only two colours. Is there a way to prevent the icon from being selected?
You can add additional images to the QIcon, depending on it's state:
QIcon icon(...);
icon.addFile("selected.png", size, QIcon::Selected);
See also the documentation of QIcon::addFile().
Best solution was to make your own qstyle which handled the painting of the backgrounds of listitem sub controls and draw the icons qrect as white
Another possibility would be to reimplement QListWidgetItem... You could therefore have a bigger control on how things gets done during the process of selection and painting...
Of course, it's a lot more work...