PDA

View Full Version : random color and lineedit



smemamian
7th April 2013, 15:12
hi
i has a button and a lineedit .
how do i change color lineedit per click ?

aamer4yu
7th April 2013, 15:39
Quick way to be use stylesheets.

You can also change palette of the lineedit.

smemamian
7th April 2013, 16:14
How do i do this? :(


void MainWindow::on_pushButton_clicked()
{

QString stirng = ui->lineEdit->text();
QString one , two , three , four ;

one = "color : red" ;
two = "color : pink" ;
three = "color : green" ;
four = "color : violet" ;


if(stirng != '\0')
{
ui->lineEdit_2->setText(stirng);
if(i==1)
{
ui->lineEdit_2->setStyleSheet(one);
i++;
}
else if(i==2)
{
ui->lineEdit_2->setStyleSheet(two);
i++;
}
else if(i==3)
{
ui->lineEdit_2->setStyleSheet(three);
i++;
}
else
{
ui->lineEdit_2->setStyleSheet(four);
i = 1 ;
}
}
}

int MainWindow::i = 1 ;

But not useful :(

ChrisW67
8th April 2013, 03:21
What happens when you single-step through this code in your debugger? What do you think line 13 does?

smemamian
8th April 2013, 09:32
What do you think line 13 does?
When the user does not enter a string in qlineedit1 :-?

8898

BalaQT
8th April 2013, 10:41
use isEmpty() to check the LineEdit text
ex:

if( !stirng.isEmpty())
{
.............
}