Results 1 to 5 of 5

Thread: changing name of a CheckBox by 2 time left clicking

  1. #1
    Join Date
    Nov 2015
    Posts
    128
    Thanks
    70
    Qt products
    Qt5
    Platforms
    Windows

    Default changing name of a CheckBox by 2 time left clicking

    Hi

    thre is a Check Box (object of QChecjBox). I want to change it's name and set my desired name by typing.
    for example i have this:

    Qt Code:
    1. ch.setText("hi");
    2. ch.show();
    To copy to clipboard, switch view to plain text mode 

    now i need when "ch" is showing, change it's name by clicking 2 times on it. I think I must create SIGNAL and SLOT for this.
    Thanks for any help

  2. #2
    Join Date
    May 2015
    Posts
    66
    Thanks
    10
    Thanked 17 Times in 17 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: changing name of a CheckBox by 2 time left clicking

    You can add a QLineEdit next to QCheckbox (without text) and that can handle text editing.

  3. The following user says thank you to Vikram.Saralaya for this useful post:

    Alex22 (2nd December 2015)

  4. #3
    Join Date
    Nov 2015
    Posts
    128
    Thanks
    70
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: changing name of a CheckBox by double left clicking

    @Vikram, thanks for your answer
    but I need the name be static (like a Label) and by double clicking on it, it will be editable. if I put a QLineEdit, it will be allways editable. Am I right?
    Last edited by Alex22; 2nd December 2015 at 11:30.

  5. #4
    Join Date
    May 2015
    Posts
    66
    Thanks
    10
    Thanked 17 Times in 17 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: changing name of a CheckBox by 2 time left clicking

    The reason its not that trivial is because check box is not intuitively a GUI element whose text can be edited.

    But if you really need then there are quite a few alternatives like using a QStackedWidget and showing QLabel Vs QLineEdit on mouse click. You can refer to this for more options: https://forum.qt.io/topic/5004/make-...ng-on-it-how/3

  6. The following user says thank you to Vikram.Saralaya for this useful post:

    Alex22 (2nd December 2015)

  7. #5
    Join Date
    Nov 2015
    Posts
    128
    Thanks
    70
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: changing name of a CheckBox by 2 time left clicking

    I created my own MyCheckBox class and using a PushButton for switching to edit mode that appears LineEdit.


    Qt Code:
    1. #include "mycheckbox.h"
    2.  
    3. MyCheckBox::MyCheckBox(QWidget *parent) : QCheckBox(parent)
    4. {
    5.  
    6. }
    7.  
    8. void MyCheckBox::setname(QString d) // my new slot
    9. {
    10. setText(d);
    11. }
    12.  
    13.  
    14. main.cpp code:
    15.  
    16. QWidget wdg;
    17. MyCheckBox ch;
    18. QGridLayout lay(&wdg);
    19. lay.addWidget(&ch,0,0);
    20. lay.addWidget(&le,0,1);
    21. QObject::connect(&le, SIGNAL(textChanged(QString)), &ch, SLOT(setname(QString)));
    22.  
    23.  
    24. wdg.show();
    To copy to clipboard, switch view to plain text mode 

    any other idea?
    Last edited by Alex22; 2nd December 2015 at 18:33.

Similar Threads

  1. Replies: 0
    Last Post: 5th January 2013, 13:29
  2. Replies: 2
    Last Post: 3rd March 2012, 06:59
  3. Changing resolution at run time by qt app
    By raghavendraningoji in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 24th November 2011, 11:56
  4. Replies: 0
    Last Post: 11th January 2011, 09:00
  5. Replies: 8
    Last Post: 2nd February 2009, 12:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.