Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QComboBox and HeaderItem
Qt 6.11 is out! See what's new in the release blog

QComboBox and HeaderItem

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Dear all, I have a QComboBox with a QStandardItemModel, which contains a single item named "One".
    I want the QComboBox to have an header (I'm not sure this is the correct technical term ...) which will always be the same.

    [1] To be more precise, running the code below leads to the following output:
    "One" (as the header) + "One" (with a checkbox).

    [2] What I'm looking for is as follows:
    "Header" (as the header) + "One" (with a checkbox).

    I tried the function "model.setHorizontalHeaderItem()" but it leads to the same as [1] above.
    Please, help me.

    @#include <QApplication>
    #include <QComboBox>
    #include <QStandardItemModel>

    int main( int argc, char **argv )
    {
    QApplication app( argc, argv );

    QComboBox* comboBox = new QComboBox();

    QStandardItemModel model( 1, 1 );
    QStandardItem *item = new QStandardItem( QString("One") );

    item->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
    item->setData ( Qt::Unchecked, Qt::CheckStateRole );

    model.setItem(0, 0, item);

    model.setHorizontalHeaderItem( 0, new QStandardItem( "Header" ) );

    comboBox->setModel( &model );
    comboBox->show();

    return app.exec();
    }@

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      zeljko
      wrote on last edited by
      #2

      See QComboBox::setView , QComboBox uses QListWidget as view by default and there's no header. Set QTreeWidget as QComboBox view and there you can set header.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved