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. QTableView tab focus on cell widget

QTableView tab focus on cell widget

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 4.4k 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.
  • A Offline
    A Offline
    AndreasF
    wrote on last edited by
    #1

    Hello,

    I have setup a QTableView with my own delegate to create a cell widget. This widget contains two QDateTimeEdit elements. My problem if I tab through date/time values of first widget is that the focus leave the cell after last time value, close the editor and enter the next cell.

    How can I prevent this behavior and set focus to next QDateTimeEdit widget of the same cell?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AndreasF
      wrote on last edited by
      #2

      Here the dual value editor that is instantiated in delegate.createEditor method with

      @
      QWidget * QStyledItemDelegate::createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index )
      {
      return new EvaDualValEditor(new QDateTimeEdit(parent), new QDateTimeEdit(parent), parent);
      }
      @

      ... and it looks like in table edit mode. After tabbing (cursor on blue marked) the editor is closed and the next cell is selected.
      !http://andreas-franke.org/home/home@andreas-franke.org/public/dualValEditor.jpg(dual val editor)!

      @
      // header
      class EvaDualValEditor : public QWidget
      {
      Q_OBJECT

      public:
      explicit EvaDualValEditor(QWidget* editor1, QWidget* editor2, QWidget *parent = 0);
      ~EvaDualValEditor();

      void setValues( QVariant& param1, QVariant& param2 );

      protected:

      private:
      QHBoxLayout *horizontalLayout_2;
      QLabel *label;
      QWidget *wgt1;
      QLabel *label_2;
      QWidget *wgt2;

      void init();
      };

      // implementation

      EvaDualValEditor::EvaDualValEditor(QWidget* editor1, QWidget* editor2, QWidget* parent /= 0/)
      : QWidget(parent)
      , wgt1(editor1)
      , wgt2(editor2)
      {
      init();
      }

      EvaDualValEditor::~EvaDualValEditor()
      {
      }

      void EvaDualValEditor::init()
      {

      setFocusPolicy (Qt::StrongFocus);
      setFocusProxy(wgt1);
      setTabOrder(wgt1, wgt2);setObjectName(QString::fromUtf8("EvaDualValEditor"));

      horizontalLayout_2 = new QHBoxLayout(this);
      horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
      horizontalLayout_2->setSpacing(1);
      horizontalLayout_2->setContentsMargins(1, 1, 1, 1);

      label = new QLabel(this);
      label->setObjectName(QString::fromUtf8("label"));

      horizontalLayout_2->addWidget(label);

      wgt1->setObjectName(QString::fromUtf8("widget"));

      horizontalLayout_2->addWidget(wgt1);

      label_2 = new QLabel(this);
      label_2->setObjectName(QString::fromUtf8("label_2"));

      horizontalLayout_2->addWidget(label_2);

      wgt2->setObjectName(QString::fromUtf8("widget_2"));

      horizontalLayout_2->addWidget(wgt2);

      }

      void EvaDualValEditor::setValues( QVariant& param1, QVariant& param2 )
      {
      if (wgt1 && !param1.isNull())
      {
      qobject_cast<QDateTimeEdit*>(wgt1)->setDateTime(param1.toDateTime());
      }
      if (wgt2 && !param2.isNull())
      {
      qobject_cast<QDateTimeEdit*>(wgt2)->setDateTime(param2.toDateTime());
      }
      }
      @

      1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        you can reimplement "QStyledItemDelegate::eventFilter()":http://qt-project.org/doc/qt-4.8/qstyleditemdelegate.html#eventFilter and react on Tab and BackTab keys.
        Note the delegate is installed as an event filter on the created editor widget by default. The widget parameter should be your editor widget which you returned in createEditor().

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AndreasF
          wrote on last edited by
          #4

          hi,

          thank you for your response. But what I have to do in QStyledItemDelegate::eventFilter() when I react on the events above? The dual editor should be stay open and next QDateTimeEdit selected. I've tried a lot of things without success.

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            you can take a look into the Qt sources of QStyledItemDelegate::eventFilter(). There you can see that some signals are fired which result in the closing of the editor.
            I especially mean these "signals":http://qt-project.org/doc/qt-4.8/qabstractitemdelegate.html#signals.
            These are triggered by the default implementation of eventFilter() in the delegate.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            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