PDA

View Full Version : How to change the color of lineedit border



Harini
22nd November 2013, 10:43
Hello everyone :)

I'm using Qt 4.7. I want a main window of size 272x380 with a line edit widget in it of completely black color(total window and lineedit). But here i'm unable to change the color of line edit border :confused:
Here is my code and screen shot attached....As displayed in the screenshot I need that red shaded border also black. I tried different types of code but i din't get it.Can any one please help me regarding this issue?? :confused: :confused:


#include <QtGui/QApplication>
#include "mainwindow.h"
#include <QLineEdit>


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLineEdit *LineEdit = new QLineEdit;
LineEdit->setStyleSheet("border: black");
//LineEdit->setStyleSheet("border: 1px solid black");


//LineEdit->setStyleSheet("QLineEdit{background: black;}");
// ("QLineEdit { background-color : rgb(45, 45, 45); }");
//LineEdit>setStyleSheet("QLineEdit{background: black;}");


QMainWindow window;
window.setWindowFlags(Qt::WindowTitleHint | Qt::FramelessWindowHint);
window.setWindowTitle(" ");
window.setFixedSize(272,480);

MainWindow w;
w.show();
return a.exec();
}

#include "mainwindow.h"
#include "ui_mainwindow.h"


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent, Qt::FramelessWindowHint),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setStyleSheet("background-color:rgb(13, 13, 13);");
// this->setStyleSheet("QLineEdit{foregroundRole-color : rgb(244, 244, 244); }");

//this->setStyleSheet("QLineEdit{border: black;}");


}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();

protected:
void changeEvent(QEvent *e);

private:
Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

derrickbj
23rd November 2013, 03:27
You seem to make the window frameless, but did you try that with the LineEdit? QLineEdit::setFrame(false); Set a styleSheet on the LineEdit as well, similar to how you set it for the window

Harini
25th November 2013, 06:02
@ Derrickbj


Thanks for ur reply :)

I did as u suggested but still facing the same problem :( I'm not getting any frame less line edit can u please help me??? :confused: :confused:

Harini
25th November 2013, 11:46
Hii all :)


I tried the following code by using inheritance concept ,project is getting compiled without any errors and warnings but I'm not getting any executed file :confused: I even tried some other code,at least to change the color of the frame by using stylesheet nothing is working here....How to get a frame less line edit in a frame less black colored window ?? :confused: :confused: anyone please help me ....


#include <QtGui/QApplication>
#include "mainwindow.h"
#include <QLineEdit>


int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QLineEdit *LineEdit = new QLineEdit;

LineEdit->setFrame("False");


//LineEdit->setAttribute(Qt.WA_MacShowFocusRect, 0);
QMainWindow window;
window.setWindowFlags(Qt::WindowTitleHint | Qt::FramelessWindowHint);
window.setWindowTitle(" ");
window.setFixedSize(272,480);

MainWindow w;
w.show();
return a.exec();
}


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);

~MainWindow();

protected:
void changeEvent(QEvent *e);


private:
Ui::MainWindow *ui;
};

class LineEdit : public QMainWindow {
Q_OBJECT
public:
void setFrame ( bool );

};

#endif // MAINWINDOW_H
//QLineEdit::setFrame(false);
//void QLineEdit::setFrame ( bool ) [virtual slot]



#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLineEdit>


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent, Qt::FramelessWindowHint),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setStyleSheet("background-color:rgb(13, 13, 13);");

//this->ui->LineEdit->setStyleSheet("border-color:rgb(13, 13, 13);");
// this->setStyleSheet("QLineEdit{foregroundRole-color : rgb(244, 244, 244); }");

//this->setStyleSheet("QLineEdit{border: black;}");

}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}

void QLineEdit::setFrame ( bool )
{
QLineEdit::setFrame(false);
}

/*void QLineEdit::setFrame (bool )
{
QLineEdit::setFrame(false);
}*/

saman_artorious
25th November 2013, 11:56
did you check the attributes of lineEdit manually? look for its properties in your form inside your project.

Harini
25th November 2013, 12:12
@ saman_artorious

I got it :) thank you :)

saman_artorious
25th November 2013, 12:17
sorry can u please explain me in detail...

inside your form, where you design your UI, on the right side. click on the lineEdit and check its properties on the right side, should you find what you are after there.

Harini
5th December 2013, 06:41
Hi its me again :)

Actually we're working for PDA (Personal Digital Assistance)product.when I try to compile this code by keeping it in our product and trying to interface with other code,getting an error-asking some libraries.How can I include that libraries is my code correct? can anyone please help me???
include <QtGui/QApplication>
#include "mainwindow.h"
#include <QLineEdit>


int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QLineEdit *LineEdit = new QLineEdit;
LineEdit->setStyleSheet("border: black");

QMainWindow window;
window.setWindowFlags(Qt::WindowTitleHint | Qt::FramelessWindowHint);
window.setWindowTitle(" ");
window.setFixedSize(272,480);

MainWindow w;
w.show();
return a.exec();
}

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLineEdit>


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent, Qt::FramelessWindowHint),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setStyleSheet("background-color:rgb(13, 13, 13);");


}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);

~MainWindow();

protected:
void changeEvent(QEvent *e);


private:
Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H