开发者

What is the correct way to customize Icon and Text position of items in a QListView?

I'm using C++ and Qt's (4.6) model/view framework and wondering what is the correct way to change the display of items in a QListView or a class derived from QListView from:

What is the correct way to customize Icon and Text position of items in a QListView?

to:

What is the correct way to customize Icon and Text position of items in a QListView?

I'm not concerned about the sort order or 开发者_运维技巧Flow, I'm interested in the best way to correctly position the text to the right of the icon.

If this can only be done by writing a custom QStyledItemDelegate that's totally fine, I want to rule out whether this is the correct approach or whether it's best to look at setLayout or similar, example code would help.

The example application I'm looking at is the 'interview' example from qtdemo which amongst other things displays icons and text in a QListView.


In that interview demo, if you change from

list->setViewMode(QListView::IconMode);

to

list->setViewMode(QListView::ListMode);

does that give the kind of view your looking for?


You can try this way also.

void CFxDRListView::changeView(int view)
{
    setWrapping (false);

    switch(view)
    {
    case eThumbnail:
        {
            clearPropertyFlags() ;
            setViewMode(QListView::IconMode);
            setLayoutMode(QListView::Batched);
            setWrapping(true);
        }
        break;
    case eIcons:
        {
            clearPropertyFlags() ;
            setViewMode(QListView::IconMode);
            setFlow(QListView::LeftToRight);
            setLayoutMode(QListView::SinglePass);
            setWrapping(true);
            setMovement(QListView::Free);
        }
        break;
    case eList:
        {
            clearPropertyFlags() ;
            setFlow(QListView::TopToBottom);
            setViewMode(QListView::ListMode);
            setMovement(QListView::Free);
        }
        break;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜