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 ?

QCheckBox easily editable on double click ?

Scheduled Pinned Locked Moved General and Desktop
13 Posts 5 Posters 4.2k Views
  • 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.
  • G Offline
    G Offline
    Goffer
    wrote on 7 Oct 2015, 18:27 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

    T 1 Reply Last reply 9 Oct 2015, 06:36
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 7 Oct 2015, 19:55 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
      • G Offline
        G Offline
        Goffer
        wrote on 7 Oct 2015, 20:44 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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 7 Oct 2015, 22:32 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

          J 1 Reply Last reply 8 Oct 2015, 00:11
          0
          • S SGaist
            7 Oct 2015, 22:32

            Because it's something that's really rarely needed

            J Offline
            J Offline
            JKSH
            Moderators
            wrote on 8 Oct 2015, 00:11 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
            • T Offline
              T Offline
              TheBadger
              wrote on 8 Oct 2015, 06:18 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
              • G Offline
                G Offline
                Goffer
                wrote on 8 Oct 2015, 21:51 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 8 Oct 2015, 21:59 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).

                  G 1 Reply Last reply 8 Oct 2015, 22:06
                  1
                  • D dcape
                    8 Oct 2015, 21:59

                    @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).

                    G Offline
                    G Offline
                    Goffer
                    wrote on 8 Oct 2015, 22:06 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
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 8 Oct 2015, 22:59 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

                      J 1 Reply Last reply 9 Oct 2015, 00:33
                      0
                      • S SGaist
                        8 Oct 2015, 22:59

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

                        J Offline
                        J Offline
                        JKSH
                        Moderators
                        wrote on 9 Oct 2015, 00:33 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
                        • G Offline
                          G Offline
                          Goffer
                          wrote on 9 Oct 2015, 00:52 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
                          • G Goffer
                            7 Oct 2015, 18:27

                            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

                            T Offline
                            T Offline
                            TheBadger
                            wrote on 9 Oct 2015, 06:36 last edited by TheBadger 10 Sept 2015, 06:49
                            #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

                            2/13

                            7 Oct 2015, 19:55

                            topic:navigator.unread, 11
                            • Login

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