Page 1 of 2 12 LastLast
Results 1 to 20 of 25

Thread: Window colour

  1. #1
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Window colour

    Hi all
    Can any body tell me how to add colour in windows. i need 2 change the colour of windows to red from default. but im not able 2 do.

    Thank you all
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Window colour

    You mean the background? Make sure the autoFillBackground property of the widget is set to true and set a colour of your choice as QPalette::Background role of the widget's palette.

  3. #3
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Window colour

    Ya autoFillBackground is set as True. i also added
    ui.CancelButton->setBackgroundRole((QPalette::ColorRole)Qt::red ); in constructor as i need cancelButton as red. But nothing is working. Can u plz tell me how to colour the window.



    Thank you.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  4. #4
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Window colour

    Qt Code:
    1. QPalette palette;
    2. QBrush brush(QColor(255, 255, 255, 255));
    3. brush.setStyle(Qt::SolidPattern);
    4. palette.setBrush(QPalette::Active, QPalette::Base, brush); /*It is for Widget Base Background*/
    5. QBrush brush1(QColor(255, 0,0, 255));
    6. brush1.setStyle(Qt::SolidPattern);
    7. palette.setBrush(QPalette::Active, QPalette::Window, brush1);/*It is for widget Background*/
    8. palette.setBrush(QPalette::Inactive, QPalette::Base, brush);
    9. palette.setBrush(QPalette::Inactive, QPalette::Window, brush1);
    10. palette.setBrush(QPalette::Disabled, QPalette::Base, brush1);
    11. palette.setBrush(QPalette::Disabled, QPalette::Window, brush1);
    12. ui.CancelButton->setPalette(palette);
    To copy to clipboard, switch view to plain text mode 
    then Make sure the autoFillBackground property of the widget is set to true.
    hope this help!
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Window colour

    Quote Originally Posted by phillip_Qt View Post
    in constructor as i need cancelButton as red.
    Oh... a "red push button" issue You'll have to use stylesheets for that ( background-color: red; ).

  6. #6
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Smile Re: Window colour

    I ve solved the problem.

    Thank you all .
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  7. #7
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Re: Window colour

    HI all.
    I ve changed the colour of window by usning the code

    Qt Code:
    1. QPalette p( this->palette());
    2. p.setColor( QPalette::Window, QColor(Qt::black));
    3. this->setPalette(p);
    To copy to clipboard, switch view to plain text mode 
    now i need to check the window colour. if it is black i need 2 change it to gray and vice versa. i Tried to do as below but its not working

    Qt Code:
    1. if(QMainWindow::backgroundRole() == Qt::black)
    2. {
    3. QPalette p( this->palette());
    4. p.setColor( QPalette::Window, QColor(Qt::gray));
    5. this->setPalette(p);
    6. }
    To copy to clipboard, switch view to plain text mode 
    But its not coming inside if loop.
    Can any body help me.
    thank you all.
    Last edited by jpn; 27th February 2008 at 09:11. Reason: missing [code] tags
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Window colour

    Read what QWidget::backgroundRole does. It returns a role, not a colour.

  9. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Window colour

    QWidget::backroundRole() returns QPalette::ColorRole. It makes no sense to compare it to Qt::GlobalColor.

    Qt Code:
    1. if (palette().color(Qt::Window) == Qt::black)
    2. ...
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  10. #10
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Window colour

    I tried to do like following.
    Qt Code:
    1. if(palette.color(QPalette::Window) == Qt::black)
    2. {
    3. GrayColour();
    4. }
    To copy to clipboard, switch view to plain text mode 
    still its not coming inside, but it showd come inside as the windows colour is black.

    Then what to do Mr Wysota.? can u plz help me.

    Thanks.
    Last edited by jpn; 27th February 2008 at 10:42. Reason: two posts merged
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Window colour

    Have a boolean flag instead of checking the colour.

  12. #12
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: Window colour

    Quote Originally Posted by wysota View Post
    Have a boolean flag instead of checking the colour.
    Thank for the Reply. Actually my requirment is if i run my programm the back grond colour of the system should change to gray including the IDE colour. But in my case only output window colour is getting changed.

    Can u plz help me, how to do this.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Window colour

    You won't be able to change colours of other applications using Qt code.

  14. #14
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: Window colour

    Quote Originally Posted by wysota View Post
    You won't be able to change colours of other applications using Qt code.
    Actully in MFC it can be done by using SetSysColor(). i need to know is there any replacment for this in Qt.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Window colour

    As I said, you won't be able to modify the behaviour of other applications using Qt code. SetSysColor() is not an MFC method, it's WinAPI function, so you can call it from Qt-based applications as well.

  16. #16
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Window colour

    Quote Originally Posted by wysota View Post
    As I said, you won't be able to modify the behaviour of other applications using Qt code. SetSysColor() is not an MFC method, it's WinAPI function, so you can call it from Qt-based applications as well.
    Can u plz tell me an example how to call Win32 API in Qt.

    Thanx
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  17. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Window colour

    Just call the function

  18. #18
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Window colour

    I tried to call like

    quint32 m_ColourElement = COLOR_3DDKSHADOW;
    quint32 m_ColourNight = RGB(100, 100, 100);
    SetSysColors(16, m_ColourElement, m_ColourDay);


    But getting erors.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  19. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Window colour

    What kind of errors?

  20. #20
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Window colour

    Quote Originally Posted by phillip_Qt View Post
    Can u plz tell me an example how to call Win32 API in Qt.
    Qt is not a programming language but a library.

    Quote Originally Posted by phillip_Qt View Post
    I tried to call like

    quint32 m_ColourElement = COLOR_3DDKSHADOW;
    quint32 m_ColourNight = RGB(100, 100, 100);
    SetSysColors(16, m_ColourElement, m_ColourDay);


    But getting erors.
    Perhaps you should read SetSysColors() docs...
    J-P Nurmi

Similar Threads

  1. Set a window as child at runtime
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 26th November 2007, 09:30
  2. Change shape of window / animate window
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 31st October 2007, 08:16
  3. Replies: 1
    Last Post: 11th September 2007, 13:34
  4. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 08:41
  5. background colour
    By kw in forum Qt Programming
    Replies: 6
    Last Post: 11th April 2006, 00:44

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.