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] QTreeWidgetItem question, i don't want all the columns editable.
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QTreeWidgetItem question, i don't want all the columns editable.

Scheduled Pinned Locked Moved General and Desktop
11 Posts 2 Posters 4.0k 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.
  • X Offline
    X Offline
    xmaze
    wrote on last edited by
    #1

    Hi to everyone, i am new in this forum.
    I made a Qtreewidget with items but i don't want to make all the columns editable.

    this is the code @QTreeWidgetItem *treeItem = new QTreeWidgetItem(ui->treeWidget);

    for(int i=0; i<13;i++) {
    treeItem->setTextAlignment(i,Qt::AlignHCenter);
    }

    // QTreeWidgetItem::setText(int column, const QString & text)

    treeItem->setText(Count, a.toUpper());
    treeItem->setFlags(Qt::ItemIsEditable|Qt::ItemIsEnabled|Qt::ItemIsUserCheckable);@

    i have for example a checkbox and if i make double click then it is editable. i found this very bad!
    !http://tinypic.com/r/ddz4vd/8()!

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xmaze
      wrote on last edited by
      #2

      Hi again, i have written some more code but the App crashes with SIGABRT signal.

      @void MainWindow::checkValues(QTreeWidgetItem *item, int column) // SLOT emited from SIGNAL itemchanged()
      {
      if(column==4) checkByte(item->text(column),column,item);

      }
      void MainWindow::checkByte(QString byte, int column, QTreeWidgetItem* item)
      {
      bool *ok; QString *b;
      b=&byte;
      int bytetoint = b->toUInt(ok,16);
      if(bytetoint>255) {
      QMessageBox::warning(this,"ERROR","Byte"+byte.setNum(column-3)+" it's higher than 255 or FF");

          item->setText(column,"FF");
      }
      

      }
      @

      When the program exits the checkByte() function crashes, i cannot understand what, i tried to set blocksignal() but its not helps. i thougt that is a infinite loop between itemchanged and item->setText...any ideas ? i am not also sure if i pass correct the item pointer from checkValues to checkByte!

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

        ok is not initialized and why b ?

        @
        bool ok;
        int bytetoint = byte.toUInt(&ok,16);
        @

        By the way, why not use a validator ? That check won't be necessary

        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
        • X Offline
          X Offline
          xmaze
          wrote on last edited by
          #4

          [quote author="SGaist" date="1416478426"]ok is not initialized and why b ?

          @
          bool ok;
          int bytetoint = byte.toUInt(&ok,16);
          @

          By the way, why not use a validator ? That check won't be necessary[/quote]
          if i use byte.toUint() then the app crashes, do you mean that i need to use byte as pointer and not as object ?
          why you said ok its not intialized? after the conversion it changes to True.

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

            [quote author="xmaze" date="1416477611"]
            @
            void MainWindow::checkByte(QString byte, int column, QTreeWidgetItem* item)
            {
            bool *ok; QString *b; << ok as well as b are uninitialized pointers
            b=&byte;
            int bytetoint = b->toUInt(ok,16); << b->toUint is the same as byte.toUInt
            @
            [/quote]

            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
            • X Offline
              X Offline
              xmaze
              wrote on last edited by
              #6

              Hi, i understood what you meant, that was my first approach, but the App crashes. i embedded a time elapse with debugging.

              if i made this trick with pointer the i dont have problem. i am running under Fedora 20.

              http://tinypic.com/r/21l0j2b/8

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

                What does a run trough the debugger show you ?

                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
                • X Offline
                  X Offline
                  xmaze
                  wrote on last edited by
                  #8

                  Problem found, i made a big mistake but i did not see that.

                  My Code was @ bool * ok
                  int bytetoint = byte.toUint(ok,16);@

                  i change that to @ bool ok
                  int bytetoint = byte.toUint(&ok,16);@

                  now its working, Thank you a lot, it was a big mistake from me!!

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

                    You're welcome !

                    Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

                    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
                    • X Offline
                      X Offline
                      xmaze
                      wrote on last edited by
                      #10

                      Ok, but i have some other questions, need to make a new thread ?

                      I want to know in closeEvent() function who is the sender, i have 2 widget and i want to close both of them if one widget is closed.
                      but if i have Qdialogbox to ask if the user is sure, then i have a spam annoying dialogbox! the QObject::sender() not working!

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

                        Yes, a new thread would be better.

                        Because closeEvent is not a slot so there's no sender. A global hint for Qt: when a function has Event in it's name, it's not a slot.

                        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

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved