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. QCheckBox easily editable on double click ?
Forum Updated to NodeBB v4.3 + New Features

QCheckBox easily editable on double click ?

Scheduled Pinned Locked Moved General and Desktop
13 Posts 5 Posters 4.4k Views 4 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.
  • GofferG Offline
    GofferG Offline
    Goffer
    wrote on last edited by
    #1

    Hi community !

    I am wondering if there is an easy way to make a QChechBox label editable like we can do with a list item by set setting a flag. I don't want to create a subClass.

    Thx

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

      Hi,

      No there's no easy way like that.

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

        That's crap ... I don t understand why it's not a default feature on each widget that holds a label ...

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

          Because it's something that's really rarely needed

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

          JKSHJ 1 Reply Last reply
          0
          • SGaistS SGaist

            Because it's something that's really rarely needed

            JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            @Goffer, could you describe why you need this feature? Why does you want your user need to change a checkbox label?

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

            1 Reply Last reply
            0
            • TheBadgerT Offline
              TheBadgerT Offline
              TheBadger
              wrote on last edited by
              #6

              Perhaps try something like adding a Checkbox without text in line with a QLineEdit, styled like a Label and then edit the line edit when double clicked.

              Just a suggestion, not tested.


              Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

              1 Reply Last reply
              0
              • GofferG Offline
                GofferG Offline
                Goffer
                wrote on last edited by
                #7

                Well I m creating a 'to do list' so when the user adds a task in his list (He can attach comments to his task) and then he realizes that his task doesn t have the correct name. Of course he could delete it and re create it but he would lose the attached comment so I want to be able to rename it by doubleClicking.

                I might try something like suggested by @TheBadger .

                @SGaist : because it would not be used ofter doesn t mean that it is useless ^^ and I think it would be very useful to be able to rename all widgets that contain a label.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dcape
                  wrote on last edited by
                  #8

                  @Goffer said:

                  so I want to be able to rename it by doubleClicking

                  You could also popup a UI that would allow the user to edit the field when you double click. It could also have the text larger (if that helped).

                  GofferG 1 Reply Last reply
                  1
                  • D dcape

                    @Goffer said:

                    so I want to be able to rename it by doubleClicking

                    You could also popup a UI that would allow the user to edit the field when you double click. It could also have the text larger (if that helped).

                    GofferG Offline
                    GofferG Offline
                    Goffer
                    wrote on last edited by
                    #9

                    @dcape

                    Yep I had that in mind as a last choice ^^ but it doesn't look very professional in my opinion

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

                      Todo - List ? Looks like a job for QListView and a column of checkbox no ?

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

                      JKSHJ 1 Reply Last reply
                      0
                      • SGaistS SGaist

                        Todo - List ? Looks like a job for QListView and a column of checkbox no ?

                        JKSHJ Offline
                        JKSHJ Offline
                        JKSH
                        Moderators
                        wrote on last edited by
                        #11

                        @SGaist said:

                        Todo - List ? Looks like a job for QListView and a column of checkbox no ?

                        Or a QListView plus a QListModel with checkable items.

                        QCheckBox's main purpose is to let users choose from a set of predefined options. This is different from a Todo list, whose main purpose is to let users define their own items.

                        @Goffer said:

                        I think it would be very useful to be able to rename all widgets that contain a label.

                        If you want, you can subscribe to the Development mailing list and present your idea to the Qt engineers. (Note: Personally, I don't think that all labelled widgets should allow editing -- programmers should choose the appropriate tool for their use case)

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

                        1 Reply Last reply
                        0
                        • GofferG Offline
                          GofferG Offline
                          Goffer
                          wrote on last edited by
                          #12

                          @SGaist I thought about that but i'm doing something more complex than a simple to do list. I have some more features that make the use of QListView non efficient as I would have to modify it too much.

                          @JKSH In my case the checkBox is used to let the user choose from a set of defined options, finished/not finished and this option influences an other widget but still it also define an item... I guess I ll go for the popup Field that will let the user rename.

                          Thx

                          1 Reply Last reply
                          0
                          • GofferG Goffer

                            Hi community !

                            I am wondering if there is an easy way to make a QChechBox label editable like we can do with a list item by set setting a flag. I don't want to create a subClass.

                            Thx

                            TheBadgerT Offline
                            TheBadgerT Offline
                            TheBadger
                            wrote on last edited by TheBadger
                            #13

                            @Goffer
                            So I played around with the Idea and this is what I ended up with:

                            Subclass QLineEdit as follow:

                            class MyLabel : public QLineEdit {
                                Q_OBJECT
                            public:
                                MyLabel(const QString& text, QWidget* parent = nullptr) 
                                    : QLineEdit(text, parent)
                                {
                                    setReadOnly(true);
                                    setStyleSheet("QLineEdit:read-only {"
                                                         "    border: none;"
                                                         "    background: transparent; }"
                                                         "QLineEdit {"
                                                         "    background: white; }");
                                    connect(this, &QLineEdit::editingFinished, [this]{
                                        this->unsetCursor();
                                        this->setSelection(0,0);
                                        this->setReadOnly(true);});
                                }
                                virtual ~MyLabel() {}
                            signals:
                                void clicked();
                            protected:
                                void mousePressEvent(QMouseEvent *) { emit clicked(); }
                                void mouseDoubleClickEvent(QMouseEvent *) {
                                    this->setReadOnly(false);
                                    this->selectAll();
                                }
                            };
                            

                            Then use as follow:

                            
                                QWidget* widget = new QWidget();
                                QHBoxLayout* layout = new QHBoxLayout();
                                widget->setLayout(layout);
                                QCheckBox* checkbox = new QCheckBox();
                                MyLabel* label = new MyLabel("Rename me");
                                connect(label, &MyLabel::clicked, checkbox, &QCheckBox::toggle);
                                layout->addWidget(checkbox);
                                layout->addWidget(label);
                                widget->show();
                            

                            Click the label or the checkbox to change the state. Double click the label to rename (you need c++11, if you can't, recode the lambda to be a member function). When renaming the label, press enter or on another control (switch focus) to finish editing the label (edit)

                            That should do what you need, the only annoyance is that if you double click the label to edit it it also changes the state of the checkbox. But you can play around with this to get you started.

                            PS: I did not comment the code, it should be self explanatory. If not just ask and I will gladly help

                            Regards,


                            Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

                            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