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. QStyledItemDelegate. Cell isn't selectable
Forum Updated to NodeBB v4.3 + New Features

QStyledItemDelegate. Cell isn't selectable

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 310 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.
  • B Offline
    B Offline
    BrMisha
    wrote on last edited by
    #1

    Hi!
    I'm using QStyledItemDelegate as delegate for view for some columns.
    If i process a cell in QStyledItemDelegate::paint then that isn't selectable.
    Code:

    void EditModeWidgetsDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    {
    	switch (static_cast<EditModeWidgetsModel::Column>(index.column())) {
    		case EditModeWidgetsModel::Column::X: [[fallthrough]];
    		case EditModeWidgetsModel::Column::Y: [[fallthrough]];
    		case EditModeWidgetsModel::Column::Width: [[fallthrough]];
    		case EditModeWidgetsModel::Column::Height: {
    			QStyleOptionMenuItem	mItem;
    			mItem.text = QString::number(index.data().toReal(), 'f', 2);
    			mItem.rect = option.rect;
    			QApplication::style()->drawControl(QStyle::CE_MenuBarItem, &mItem, painter);
    		} break;
    		default: QStyledItemDelegate::paint(painter, option, index);
    	}
    }
    

    Where is my misstate?
    Thanks)))

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @BrMisha said in QStyledItemDelegate. Cell isn't selectable:

      Where is my misstate?

      You're not copying the style options from the given option.

      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
      3
      • eyllanescE Offline
        eyllanescE Offline
        eyllanesc
        wrote on last edited by eyllanesc
        #3

        @BrMisha sThe paint method invokes initStyleOption which loads configurations as if the item is selected or not, etc, but you don't use it causing that error. If you just want to change the text then just override initStyleOption:

        void EditModeWidgetsDelegate::initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const
        {
               QStyledItemDelegate::initStyleOption(option, index);
        	switch (static_cast<EditModeWidgetsModel::Column>(index.column())) {
        		case EditModeWidgetsModel::Column::X: [[fallthrough]];
        		case EditModeWidgetsModel::Column::Y: [[fallthrough]];
        		case EditModeWidgetsModel::Column::Width: [[fallthrough]];
        		case EditModeWidgetsModel::Column::Height: {
        			option->text = QString::number(index.data().toReal(), 'f', 2);
        		} break;
        	}
        }
        

        If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

        1 Reply Last reply
        2
        • B Offline
          B Offline
          BrMisha
          wrote on last edited by
          #4

          Thanks, men! You solved my problem)))

          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