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. Custom TableWidget QHeaderView
Qt 6.11 is out! See what's new in the release blog

Custom TableWidget QHeaderView

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 630 Views
  • 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.
  • I Offline
    I Offline
    IknowQT
    wrote on last edited by
    #1
    class QCustomTableView : public QTableWidget
    {
    	Q_OBJECT
    
    private:
    	QHeaderView*	m_pHeaderview;
    
    public:
    	QCustomTableView(QObject* parent);
    	QCustomTableView(Qt::Orientation orientation, QObject *parent);
    }
    
    QCustomTableView::QCustomTableView(Qt::Orientation orientation, QObject *parent)
    {
    	m_pHeaderview = new QHeaderView(orientation, this);
    	this->setHorizontalHeader(m_pHeaderview);
            this->setEditTriggers(QAbstractItemView::EditTrigger::NoEditTriggers);		
    	this->horizontalHeader()->setStretchLastSection(true);
    
    QString strStyle("\
    				QHeaderView::section\
    				{\
    					background-color: #00599C;\
    					padding: 4px;\
    					border: 40px;\
    					border-color: red;\
    					font-family: Microsoft YaHei UI;\
    					font-size: 10pt;\
    					color: #FFFFFF;\
    				}\
    				QTableWidget\
    				{\
    					gridline-color: #003863;\
    					font-size: 10pt;\
    					border: 4px;\
    					border-color: #002039;\
    				}\
    				QTableWidget QTableCornerButton::section\
    				{\
    					background-color: #00599C;\
    					border: 4px solid #003863;\
    				}\
    		");
    
    	this->setStyleSheet(strStyle);
    }
    

    I made a customized table widget, but the horizontal header is not accessible and null, so I made a new one and put it in the set horizontal header.
    But the style sheet didn't work. I used to check the style sheet.

    Is there a way?

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      my m_tableWidget->horizontalHeader() is not null. Why is yours null? Which Qt version? Mine is Qt 5.15.2.

      1 Reply Last reply
      2

      • Login

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