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 insert QCheckbox into center of items in a QTableView?

how to insert QCheckbox into center of items in a QTableView?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 205 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.
  • Y Offline
    Y Offline
    yangyanhui4
    wrote on last edited by
    #1

    Hi,I have a tableview and insert a QCheckbox into the item of the second column. I use model-view-control frame to display the data.

    in data() of the model file:
    if (role == Qt::TextAlignmentRole)
    {
    switch (column) {
    case 0: {
    return int(Qt::AlignLeft|Qt::AlignVCenter);
    break;
    }
    case 1:
    {
    return int(Qt::AlignCenter);
    break;
    }
    }
    }

    I use the following code to set the alignment of the checkbox to be in the center of the item but with no use?
    what should I do to set the alignment?

    Christian EhrlicherC 1 Reply Last reply
    0
    • Y yangyanhui4

      Hi,I have a tableview and insert a QCheckbox into the item of the second column. I use model-view-control frame to display the data.

      in data() of the model file:
      if (role == Qt::TextAlignmentRole)
      {
      switch (column) {
      case 0: {
      return int(Qt::AlignLeft|Qt::AlignVCenter);
      break;
      }
      case 1:
      {
      return int(Qt::AlignCenter);
      break;
      }
      }
      }

      I use the following code to set the alignment of the checkbox to be in the center of the item but with no use?
      what should I do to set the alignment?

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @yangyanhui4 said in how to insert QCheckbox into center of items in a QTableView?:

      what should I do to set the alignment?

      You need a custom QStyledItemDelegate.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      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