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. QStyledItemDelagete DecorationAlignment Do Not Work
Forum Updated to NodeBB v4.3 + New Features

QStyledItemDelagete DecorationAlignment Do Not Work

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 361 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.
  • D Offline
    D Offline
    DzCode
    wrote on last edited by
    #1

    Hi everyone,

    in qtableview, I want decoration role to be displayed in the center of the cell
    However, decorationalignment of QStyledItemDelegate do not work.

    I have a custom delegate class and the code about decoration role is like below.
    It is weird that decorationPosition is working, but it does not have centering the content (top right bottom left). decorationAlignment do not work. Also, I tried it in paint event but it also fails.

    void StyledItemDelegate::initStyleOption(QStyleOptionViewItem *in_p_option, const QModelIndex &in_index) const
    {
        QStyledItemDelegate::initStyleOption(in_p_option,in_index);
        if (m_features & DecorationCenter)
        {
            in_p_option->decorationAlignment = Qt::AlignCenter;
        }
    
    }
    
    1 Reply Last reply
    2
    • D Offline
      D Offline
      DzCode
      wrote on last edited by
      #2

      Hi everyone,

      I solved the problem.

      in_p_option->decorationSize plays key role in this. before centering alignment decoration size should be changed also.

      By code is like below.

      QTableView *p_table = dynamic_cast<QTableView *>(in_index.model()->parent());
      in_p_option->decorationSize = QSize(p_table->columnWidth(in_index.column()),p_table->verticalHeader()->defaultSectionSize());
              in_p_option->decorationAlignment = Qt::AlignCenter;
      
      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