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. [SOLVED] Insert row from Qtableview to another
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Insert row from Qtableview to another

Scheduled Pinned Locked Moved General and Desktop
68 Posts 3 Posters 34.6k 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
    advseo32
    wrote on last edited by
    #21

    if i can't use keypressevent() as a signal

    how i can handle this event " when the uesr click Key_Down new row added in the bottom "

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #22

      It is explained in the function documentation

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        advseo32
        wrote on last edited by
        #23

        i still can't know what i do ,

        subclass Qtablewidget and implement keypressevent
        or use shortcuts .

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #24

          You can also use an event filter to catch that event, this really is up to you to choose the solution that meets your need

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            advseo32
            wrote on last edited by
            #25

            i have implemented keypressEvent function

            and it works perfectly, but when i start to somme conditions the programme crashes

            her is my code @void MonTableauWidget::keyPressEvent(QKeyEvent *event)
            {
            int LastRow = this->rowCount();

            switch (event->key()) {
            case Qt::Key_Down :
            // the problem occured  when i added the line below if(!this->item(LastRow,0)->text().isEmpty())
                this->insertRow(this->rowCount());
                break;
            case Qt::Key_Up :
             this->removeRow(1);
                break;
            case Qt::Key_0 :
            
                QMessageBox::information(this,"Row coutn",QString::number( LastRow)) ;
                break;
            default:
                QTableWidget::keyPressEvent(event);
                break;
            }
            

            }
            @

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #26

              @removeRow(1); << What would happen if you don't have a row number 1 ?@

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • A Offline
                A Offline
                advseo32
                wrote on last edited by
                #27

                i have used the debugger to determine what's the issue
                and i think the issue is located her
                because when i delete this line every thing works perfectly
                @this->item(LastRow,0)->text().isEmpty() ;@

                this not refering to the customQtableWidget it's reffering to the
                QtableWidgetItem objet

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  advseo32
                  wrote on last edited by
                  #28

                  [quote author="SGaist" date="1374875944"]@removeRow(1); << What would happen if you don't have a row number 1 ?@[/quote]

                  nothing is happened , means no row have to removed , but i have correct this issue

                  @this->removeRow(this->rowCount()-1); @
                  and this should works , and finally it works

                  thank's for the hint

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    advseo32
                    wrote on last edited by
                    #29

                    her is my finall code @void MonTableauWidget::keyPressEvent(QKeyEvent *event)
                    {
                    int LastRow = this->rowCount()-1;

                    // bool ok = this->item(LastRow,0)->text().isEmpty() ;

                    switch (event->key()) {
                    case Qt::Key_Down :
                        if(LastRow)
                            this->insertRow(this->rowCount());
                        break;
                    case Qt::Key_Up :
                     this->removeRow(LastRow);
                        break;
                    default:
                        QTableWidget::keyPressEvent(event);
                        break;
                    }
                    

                    @

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      advseo32
                      wrote on last edited by
                      #30

                      i lost hope to get the solution from my self,

                      the only problem now is how to test if Cell is Empty

                      i use this

                      @this->item(row,col)->text().isEmpty(); @

                      but the programme crashes , what the probleme her ??

                      1 Reply Last reply
                      0
                      • JKSHJ Offline
                        JKSHJ Offline
                        JKSH
                        Moderators
                        wrote on last edited by
                        #31

                        [quote author="advseo32" date="1374923562"]
                        @this->item(row,col)->text().isEmpty(); @

                        but the programme crashes , what the probleme her ??[/quote]If there is no data in the cell, then this->item() returns NULL.

                        Your program will crash if you dereference a null pointer.

                        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          advseo32
                          wrote on last edited by
                          #32

                          [quote author="JKSH" date="1374928103"][quote author="advseo32" date="1374923562"]
                          @this->item(row,col)->text().isEmpty(); @

                          but the programme crashes , what the probleme her ??[/quote]If there is no data in the cell, then this->item() returns NULL.

                          Your program will crash if you dereference a null pointer.

                          [/quote]

                          Yeah! that's true , because QTableWidgetItem was created only when the user fill in the cell

                          do you have another way to check if the cell if not empty

                          1 Reply Last reply
                          0
                          • JKSHJ Offline
                            JKSHJ Offline
                            JKSH
                            Moderators
                            wrote on last edited by
                            #33

                            [quote author="advseo32" date="1374942257"]do you have another way to check if the cell if not empty [/quote]If there is no data in the cell, then this->item() returns NULL :)

                            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              advseo32
                              wrote on last edited by
                              #34

                              [quote author="JKSH" date="1374942566"][quote author="advseo32" date="1374942257"]do you have another way to check if the cell if not empty [/quote]If there is no data in the cell, then this->item() returns NULL :)[/quote]

                              Probably , you have give the answer from the the begning , but i haven't pay attention to it

                              yes it's works
                              @if (this->item(LastRow,0) != 0)@

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                advseo32
                                wrote on last edited by
                                #35

                                now

                                i want to change the behavior of vertical header in Qtableview

                                this is what i mean:

                                when user start fill table cells, i want this sign(*) present in vertical header instead of numbers

                                when user moves beteween rows , i want also this sign(>) present in vertical header instead of numbers

                                what function i need to implement

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #36

                                  Did you read the documentation of the various classes you are using ? For example "cellChanged":http://qt-project.org/doc/qt-4.8/qtablewidget.html#cellChanged ?

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  0
                                  • A Offline
                                    A Offline
                                    advseo32
                                    wrote on last edited by
                                    #37

                                    yes i did, but what functions are responsible for doing this

                                    sign(*) present in vertical header instead of numbers

                                    sign(>) present in vertical header instead of numbers

                                    1 Reply Last reply
                                    0
                                    • JKSHJ Offline
                                      JKSHJ Offline
                                      JKSH
                                      Moderators
                                      wrote on last edited by
                                      #38

                                      [quote author="SGaist" date="1374952377"]Did you read the documentation of the various classes you are using ?
                                      [quote author="advseo32" date="1374964095"]yes i did, but what functions are responsible for...[/quote][/quote]Please read more thoroughly.

                                      Go to the "documentation":http://qt-project.org/doc/qt-5.1/qtwidgets/qtablewidget.html again and search for "header". Try different functions with good names to see what they do.

                                      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                      1 Reply Last reply
                                      0
                                      • A Offline
                                        A Offline
                                        advseo32
                                        wrote on last edited by
                                        #39

                                        i have try many functions but no result

                                        Her is my try
                                        this function called when the user start editing cell "CellChanged Signal"
                                        @
                                        void Dialog::newfunction()
                                        {
                                        QModelIndex index ;
                                        index = tableau->model()->index(0,0) ;
                                        tableau->verticalHeader()->model()->setData(index,QPixmap("imgs/arrow.png"),Qt::DecorationRole);
                                        }

                                        @

                                        1 Reply Last reply
                                        0
                                        • JKSHJ Offline
                                          JKSHJ Offline
                                          JKSH
                                          Moderators
                                          wrote on last edited by
                                          #40

                                          Good on you for trying.
                                          [quote author="advseo32" date="1375041952"]
                                          Her is my try
                                          this function called when the user start editing cell "CellChanged Signal"
                                          @
                                          void Dialog::newfunction()
                                          {
                                          QModelIndex index ;
                                          index = tableau->model()->index(0,0) ;
                                          tableau->verticalHeader()->model()->setData(index,QPixmap("imgs/arrow.png"),Qt::DecorationRole);
                                          }

                                          @
                                          [/quote]There are two major issues:

                                          If you haven't set any header data, tableau->verticalHeader()->model() returns NULL

                                          You have 2 models here. tableau->model() is the table model, tableau->verticalHeader()->model() is the header model. You created an index for the table model, so you can't use that index to set data in the header model.

                                          Hint: If you use setHeaderData(), you don't need an index

                                          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                          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