Results 1 to 1 of 1

Thread: How to change border colors of a widget?

  1. #1
    Join Date
    Sep 2012
    Location
    Iran, Tehran
    Posts
    76
    Thanks
    17
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Question Re: How to change border colors of a widget?

    I want to change the color of right border of a widget and leave others unchanged. Is it possible? If so, How can I do that?

    In the following code
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6. QWidget window;
    7. QLineEdit line;
    8. QString st;
    9.  
    10. // line.setStyleSheet("border: 10px solid blue;"); //<----------- first
    11.  
    12. st.append("border-right: 10px solid blue;");
    13.  
    14. line.setStyleSheet(st); //<------------ second
    15.  
    16. st.append("border-top: 10px solid blue;");
    17.  
    18. // line.setStyleSheet(st); //<----------- third
    19.  
    20. st.append("border-left: 10px solid blue;");
    21. st.append("border-bottom: 10px solid blue;");
    22.  
    23. // line.setStyleSheet(st); //<------------ forth
    24.  
    25. hl.addWidget(&line);
    26. window.setLayout(&hl);
    27. window.resize(640, 480);
    28. window.show();
    29.  
    30. return app.exec();
    31. }
    To copy to clipboard, switch view to plain text mode 
    the statements marked first and forth are working as expected, the third has some effects, but the second has no effect.



    Added after 1 8 minutes:


    Consider following paragraphs from Qt's Docs http://doc.qt.io/qt-4.8/stylesheet-reference.html:
    One to four occurrences of Brush, specifying the top, right, bottom, and left edges of a box, respectively. If the left color is not specified, it is taken to be the same as the right color. If the bottom color is not specified, it is taken to be the same as the top color. If the right color is not specified, it is taken to be the same as the top color. Example:
    QLabel { border-color: red } /* red red red red */
    QLabel { border-color: red blue } /* red blue red blue */
    QLabel { border-color: red blue green } /* red blue green blue */
    QLabel { border-color: red blue green yellow } /* red blue green yellow */
    border-color The color of all the border's edges. Equivalent to specifying border-top-color, border-right-color, border-bottom-color, and border-left-color.
    border-right Shorthand notation for setting the widget's right border. Equivalent to specifying border-right-color, border-right-style, and/or border-right-width.
    There's similar statements for width and style.
    Now, isn't this in contradiction to the what happens in the example of first post?
    Last edited by Ashkan_s; 16th October 2012 at 10:39.

Similar Threads

  1. change colors using Qpainter during run time
    By sandeep_hyd123 in forum Newbie
    Replies: 5
    Last Post: 9th June 2011, 23:05
  2. Widget Resizable Border
    By ale6111 in forum Qt Programming
    Replies: 3
    Last Post: 22nd July 2010, 17:20
  3. Change QTableView border colour under special cicrumstances
    By stefanadelbert in forum Qt Programming
    Replies: 0
    Last Post: 12th April 2010, 06:52
  4. Change colors of date of calendarwidget
    By moh.gup@gmail.com in forum Qt Programming
    Replies: 0
    Last Post: 6th April 2010, 19:36
  5. How to change some colors in a QPlainTextEdit
    By aarelovich in forum Qt Programming
    Replies: 2
    Last Post: 2nd June 2009, 23:18

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.