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. how to get gray background headers of qtableview
Forum Updated to NodeBB v4.3 + New Features

how to get gray background headers of qtableview

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 864 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1
    This post is deleted!
    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      Qt Enthusiast
      wrote on last edited by Qt Enthusiast
      #2

      #include "mainwindow.h"
      #include <QHeaderView>
      #include <QTableWidgetItem>
      #include <QLabel>
      #include <QPushButton>

      myWidget::myWidget(QWidget *parent) : QWidget(NULL) {
      hbox = new QHBoxLayout;

      QLabel* label = new QLabel;
      label->setText("Options");
      label->setMaximumWidth(100);
      label->setMinimumHeight(20);
      hbox->addWidget(label);

      QPushButton* push = new QPushButton("+");
      push->setMaximumWidth(30);
      push->setMinimumHeight(20);
      hbox->addWidget(push);

      setMinimumWidth(100);
      setLayout(hbox);

      }

      MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent)
      {

      QTableWidget * t = new QTableWidget;
      t->setColumnCount(5);
      t->setRowCount(3);
      QStringList headerLabels;

      QString col1 = "Label1";
      QString col2 = "Label2";
      QString col3 = "Label3";
      QString col4 = " Label4";
      QString col5 = " Label5";
      t->setStyleSheet("QHeaderView::section { background-color:'light grey' }");

      QColor color(QColor("light grey"));
      QTableWidgetItem* item = new QTableWidgetItem("23");
      item->setData(Qt::BackgroundRole,color);

      QColor color1(QColor("light grey"));
      QTableWidgetItem* item1 = new QTableWidgetItem("9");
      item1->setData(Qt::BackgroundRole,color1);

      QTableWidgetItem* item2 = new QTableWidgetItem("Set1");
      item2->setData(Qt::BackgroundRole,color);

      QTableWidgetItem* item3 = new QTableWidgetItem("Set2");
      item3->setData(Qt::BackgroundRole,color);

      t->setItem(0,0,item);
      t->setItem(1,0,item1);
      t->setItem(0,1,item2);
      t->setItem(1,1,item3);

      QComboBox* combox = new QComboBox;
      t->setCellWidget(0,2,combox);
      combox->addItem(QString(("T1")));
      combox->addItem(QString(("T2")));

      QComboBox* combox_1 = new QComboBox;
      t->setCellWidget(1,2,combox_1);
      combox_1->addItem(QString(("T1")));
      combox_1->addItem(QString(("T2")));

      QLineEdit * edit = new QLineEdit;
      edit->setText(" aaa: aaa ");
      t->setCellWidget(0,3,edit);

      QLineEdit * edit1 = new QLineEdit;
      edit1->setText(" bbb: bbb ");
      t->setCellWidget(1,3,edit1);

      myWidget* m = new myWidget;
      t->setCellWidget(0,4,m);

      myWidget* n = new myWidget;
      t->setCellWidget(1,4,n);

      headerLabels << col1 << col2 << col3 << col4 << col5;
      t->setHorizontalHeaderLabels(headerLabels);
      t->resizeColumnsToContents();
      t->verticalHeader()->hide();
      t->show();

      }

      MainWindow::~MainWindow()
      {

      }

      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