Results 1 to 8 of 8

Thread: How to change the color of lineedit border

  1. #1
    Join Date
    Nov 2013
    Location
    Hyderabad
    Posts
    52
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to change the color of lineedit border

    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
    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??

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3. #include <QLineEdit>
    4.  
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9. QLineEdit *LineEdit = new QLineEdit;
    10. LineEdit->setStyleSheet("border: black");
    11. //LineEdit->setStyleSheet("border: 1px solid black");
    12.  
    13.  
    14. //LineEdit->setStyleSheet("QLineEdit{background: black;}");
    15. // ("QLineEdit { background-color : rgb(45, 45, 45); }");
    16. //LineEdit>setStyleSheet("QLineEdit{background: black;}");
    17.  
    18.  
    19. QMainWindow window;
    20. window.setWindowFlags(Qt::WindowTitleHint | Qt::FramelessWindowHint);
    21. window.setWindowTitle(" ");
    22. window.setFixedSize(272,480);
    23.  
    24. MainWindow w;
    25. w.show();
    26. return a.exec();
    27. }
    To copy to clipboard, switch view to plain text mode 

    #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;
    }
    }
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7. class MainWindow;
    8. }
    9.  
    10. class MainWindow : public QMainWindow {
    11. Q_OBJECT
    12. public:
    13. MainWindow(QWidget *parent = 0);
    14. ~MainWindow();
    15.  
    16. protected:
    17. void changeEvent(QEvent *e);
    18.  
    19. private:
    20. Ui::MainWindow *ui;[QTCLASS][/QTCLASS]
    21. };
    22.  
    23. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  2. #2
    Join Date
    Sep 2006
    Posts
    38
    Thanks
    5
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to change the color of lineedit border

    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

  3. #3
    Join Date
    Nov 2013
    Location
    Hyderabad
    Posts
    52
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to change the color of lineedit border

    @ 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???

  4. #4
    Join Date
    Nov 2013
    Location
    Hyderabad
    Posts
    52
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to change the color of lineedit border

    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 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 ?? anyone please help me ....

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3. #include <QLineEdit>
    4.  
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9.  
    10. QLineEdit *LineEdit = new QLineEdit;
    11.  
    12. LineEdit->setFrame("False");
    13.  
    14.  
    15. //LineEdit->setAttribute(Qt.WA_MacShowFocusRect, 0);
    16. QMainWindow window;
    17. window.setWindowFlags(Qt::WindowTitleHint | Qt::FramelessWindowHint);
    18. window.setWindowTitle(" ");
    19. window.setFixedSize(272,480);
    20.  
    21. MainWindow w;
    22. w.show();
    23. return a.exec();
    24. }
    25. [CODE]
    To copy to clipboard, switch view to plain text mode 
    #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]
    [/CODE]

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QLineEdit>
    4.  
    5.  
    6. MainWindow::MainWindow(QWidget *parent) :
    7. QMainWindow(parent, Qt::FramelessWindowHint),
    8. ui(new Ui::MainWindow)
    9. {
    10. ui->setupUi(this);
    11. this->setStyleSheet("background-color:rgb(13, 13, 13);");
    12.  
    13. //this->ui->LineEdit->setStyleSheet("border-color:rgb(13, 13, 13);");
    14. // this->setStyleSheet("QLineEdit{foregroundRole-color : rgb(244, 244, 244); }");
    15.  
    16. //this->setStyleSheet("QLineEdit{border: black;}");
    17.  
    18. }
    19. MainWindow::~MainWindow()
    20. {
    21. delete ui;
    22. }
    23. void MainWindow::changeEvent(QEvent *e)
    24. {
    25. QMainWindow::changeEvent(e);
    26. switch (e->type()) {
    27. case QEvent::LanguageChange:
    28. ui->retranslateUi(this);
    29. break;
    30. default:
    31. break;
    32. }
    33. }
    34.  
    35. void QLineEdit::setFrame ( bool )
    36. {
    37. QLineEdit::setFrame(false);
    38. }
    39.  
    40. /*void QLineEdit::setFrame (bool )
    41. {
    42.   QLineEdit::setFrame(false);
    43. }*/
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How to change the color of lineedit border

    did you check the attributes of lineEdit manually? look for its properties in your form inside your project.

  6. #6
    Join Date
    Nov 2013
    Location
    Hyderabad
    Posts
    52
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to change the color of lineedit border

    @ saman_artorious

    I got it thank you
    Last edited by Harini; 25th November 2013 at 13:17.

  7. #7
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How to change the color of lineedit border

    Quote Originally Posted by Harini View Post
    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.

  8. The following user says thank you to saman_artorious for this useful post:

    Harini (25th November 2013)

  9. #8
    Join Date
    Nov 2013
    Location
    Hyderabad
    Posts
    52
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: How to change the color of lineedit border

    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???
    Qt Code:
    1. include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3. #include <QLineEdit>
    4.  
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9.  
    10. QLineEdit *LineEdit = new QLineEdit;
    11. LineEdit->setStyleSheet("border: black");
    12.  
    13. QMainWindow window;
    14. window.setWindowFlags(Qt::WindowTitleHint | Qt::FramelessWindowHint);
    15. window.setWindowTitle(" ");
    16. window.setFixedSize(272,480);
    17.  
    18. MainWindow w;
    19. w.show();
    20. return a.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QLineEdit>
    4.  
    5.  
    6. MainWindow::MainWindow(QWidget *parent) :
    7. QMainWindow(parent, Qt::FramelessWindowHint),
    8. ui(new Ui::MainWindow)
    9. {
    10. ui->setupUi(this);
    11. this->setStyleSheet("background-color:rgb(13, 13, 13);");
    12.  
    13.  
    14. }
    15. MainWindow::~MainWindow()
    16. {
    17. delete ui;
    18. }
    19. void MainWindow::changeEvent(QEvent *e)
    20. {
    21. QMainWindow::changeEvent(e);
    22. switch (e->type()) {
    23. case QEvent::LanguageChange:
    24. ui->retranslateUi(this);
    25. break;
    26. default:
    27. break;
    28. }
    29. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7. class MainWindow;
    8. }
    9.  
    10. class MainWindow : public QMainWindow {
    11. Q_OBJECT
    12. public:
    13. MainWindow(QWidget *parent = 0);
    14.  
    15. ~MainWindow();
    16.  
    17. protected:
    18. void changeEvent(QEvent *e);
    19.  
    20.  
    21. private:
    22. Ui::MainWindow *ui;
    23. };
    24.  
    25. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 
    Last edited by Harini; 5th December 2013 at 07:49.

Similar Threads

  1. random color and lineedit
    By smemamian in forum Newbie
    Replies: 5
    Last Post: 8th April 2013, 11:41
  2. Replies: 4
    Last Post: 8th September 2011, 09:22
  3. Replies: 3
    Last Post: 22nd January 2010, 17:46
  4. How to set the BORDER COLOR of QDialog?
    By ashukla in forum Qt Programming
    Replies: 6
    Last Post: 13th November 2007, 17:09
  5. Get Color from LineEdit
    By raphaelf in forum Newbie
    Replies: 4
    Last Post: 15th May 2007, 16:30

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.