Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a Header to a QListView

I am having a QListView which has 5 items in it. say(America, Canada, Denmark, Egypt, Finland) in my QListView. Now i want to set a common Header for all this items as COUNTRIES. How can i set a Header to a QListView. Please Help.

like image 286
New Moon Avatar asked Nov 02 '22 10:11

New Moon


1 Answers

Well, you can not directly but, you can do this.

    mHb = new QHBoxLayout;
    {

        QVBoxLayout *tInnerVB = new QVBoxLayout;
        {
            QLabel *tHeader = new QLabel("Team List");
            tHeader->setFont(QFont("FontAwesome"));
            tInnerVB->addWidget(tHeader);

            mTeamViewModel->setStringList(BDatabase::instance()->getTeamList());
            mLeTeamList->setModel(mTeamViewModel);
            tInnerVB->addWidget(mLeTeamList);

        }
        mHb->addLayout(tInnerVB);

        tInnerVB = new QVBoxLayout;
        {
            QLabel *tHeader = new QLabel("Team Members");
            tHeader->setFont(QFont("FontAwesome"));
            tInnerVB->addWidget(tHeader);

            mMembersViewModel->setStringList(QStringList());
            mLeTeamMembers->setModel(mMembersViewModel);
            tInnerVB->addWidget(mLeTeamMembers);

        }
        mHb->addLayout(tInnerVB);


    }

The output would be like:

enter image description here

Moreover, you can change orientation, alignment and other things by the label. Good coding :)

like image 196
john whitegun Avatar answered Nov 15 '22 05:11

john whitegun