Results 1 to 6 of 6

Thread: random color and lineedit

  1. #1
    Join Date
    Mar 2013
    Posts
    45
    Thanks
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default random color and lineedit

    hi
    i has a button and a lineedit .
    how do i change color lineedit per click ?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: random color and lineedit

    Quick way to be use stylesheets.

    You can also change palette of the lineedit.

  3. #3
    Join Date
    Mar 2013
    Posts
    45
    Thanks
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: random color and lineedit

    How do i do this?

    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3.  
    4. QString stirng = ui->lineEdit->text();
    5. QString one , two , three , four ;
    6.  
    7. one = "color : red" ;
    8. two = "color : pink" ;
    9. three = "color : green" ;
    10. four = "color : violet" ;
    11.  
    12.  
    13. if(stirng != '\0')
    14. {
    15. ui->lineEdit_2->setText(stirng);
    16. if(i==1)
    17. {
    18. ui->lineEdit_2->setStyleSheet(one);
    19. i++;
    20. }
    21. else if(i==2)
    22. {
    23. ui->lineEdit_2->setStyleSheet(two);
    24. i++;
    25. }
    26. else if(i==3)
    27. {
    28. ui->lineEdit_2->setStyleSheet(three);
    29. i++;
    30. }
    31. else
    32. {
    33. ui->lineEdit_2->setStyleSheet(four);
    34. i = 1 ;
    35. }
    36. }
    37. }
    38.  
    39. int MainWindow::i = 1 ;
    To copy to clipboard, switch view to plain text mode 

    But not useful

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: random color and lineedit

    What happens when you single-step through this code in your debugger? What do you think line 13 does?

  5. #5
    Join Date
    Mar 2013
    Posts
    45
    Thanks
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: random color and lineedit

    What do you think line 13 does?
    When the user does not enter a string in qlineedit1 :-?

    qlineedit.jpg

  6. #6
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: random color and lineedit

    use isEmpty() to check the LineEdit text
    ex:
    Qt Code:
    1. if( !stirng.isEmpty())
    2. {
    3. .............
    4. }
    To copy to clipboard, switch view to plain text mode 

  7. The following user says thank you to BalaQT for this useful post:

    smemamian (8th April 2013)

Similar Threads

  1. random number
    By pingus in forum Qt Programming
    Replies: 3
    Last Post: 6th July 2011, 18:22
  2. Replies: 1
    Last Post: 7th April 2010, 16:26
  3. random
    By raphaelf in forum General Programming
    Replies: 9
    Last Post: 6th June 2007, 12:33
  4. opimize random
    By raphaelf in forum Newbie
    Replies: 2
    Last Post: 16th May 2007, 00:01
  5. Get Color from LineEdit
    By raphaelf in forum Newbie
    Replies: 4
    Last Post: 15th May 2007, 15:30

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.