Results 1 to 2 of 2

Thread: QLineEdit setSelecttion(int start, int length) bug? Input mask is IP address.

  1. #1
    Join Date
    Nov 2010
    Posts
    13
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QLineEdit setSelecttion(int start, int length) bug? Input mask is IP address.

    Hi guys:

    I want ot have a IP address editor , and use the Key_Left and Key_Right control the text selection between dots. Now, I set the editor like this:
    Qt Code:
    1. setInputMaks("000.000.000.000");
    2.  
    3. .....
    4. case Qt::Key_Left:
    5. if (m_selected >= 0 )
    6. {
    7. this->setSelection(m_selected, 3);
    8. if (m_selected > 3)
    9. m_selected -= 4;
    10. }
    11. break;
    12.  
    13. case Qt::Key_Right:
    14. if (m_selected <= 12)
    15. {
    16. this->setSelection(m_selected, 3);
    17. if (m_selected < 12)
    18. m_selected += 4;
    19. }
    20.  
    21. break;
    22. ...
    To copy to clipboard, switch view to plain text mode 

    It works when the input liks 192.168.1.112, but when the input is less than 9 chars (as 192.168.1.1), the Key_Right. It means I will never input the IP address like 192.168.0.XXX or else chars less than 9.

    So, is there any way to resolve this problem: the Key_Right or Key_Left selects the area between two idos.


    Added after 26 minutes:


    It works on X11, but can't be in embelded.

    Last edited by zimang; 8th December 2010 at 08:25.

  2. #2
    Join Date
    Aug 2009
    Posts
    92
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QLineEdit setSelecttion(int start, int length) bug? Input mask is IP address.

    Old thread but I have a similar problem.

    I set the selection to (0, 0) but all the text is selected anyway.
    If I comment setFocus, then no text is selected (but in that case I don't need any call to setSelection(0, 0)).


    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6.  
    7. QDialog* dg = new QDialog();
    8.  
    9. QLineEdit* le = new QLineEdit(dg);
    10. le->setText("test");
    11. le->setFocus();
    12. le->setSelection(0, 0);
    13. dg->exec();
    14.  
    15. return app.exec();
    16. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QT += gui core
    2.  
    3. TARGET = dialog
    4. TEMPLATE = app
    5.  
    6. HEADERS =
    7.  
    8. SOURCES = main.cpp
    To copy to clipboard, switch view to plain text mode 

    screenshotgps.png

Similar Threads

  1. QLineEdit and input mask
    By tpf80 in forum Qt Programming
    Replies: 7
    Last Post: 9th May 2014, 19:47
  2. Replies: 11
    Last Post: 11th July 2010, 21:44
  3. IP address input mask?
    By DiamonDogX in forum Qt Programming
    Replies: 2
    Last Post: 15th August 2009, 07:54
  4. Replies: 5
    Last Post: 10th July 2009, 12:11
  5. Mixing QRegExpValidator and input mask and QLineEdit
    By abernat in forum Qt Programming
    Replies: 1
    Last Post: 18th February 2009, 00:04

Tags for this Thread

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.