PDA

View Full Version : Window colour



phillip_Qt
26th February 2008, 13:22
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

wysota
26th February 2008, 13:24
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.

phillip_Qt
27th February 2008, 04:38
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.

ashukla
27th February 2008, 06:18
QPalette palette;
QBrush brush(QColor(255, 255, 255, 255));
brush.setStyle(Qt::SolidPattern);
palette.setBrush(QPalette::Active, QPalette::Base, brush); /*It is for Widget Base Background*/
QBrush brush1(QColor(255, 0,0, 255));
brush1.setStyle(Qt::SolidPattern);
palette.setBrush(QPalette::Active, QPalette::Window, brush1);/*It is for widget Background*/
palette.setBrush(QPalette::Inactive, QPalette::Base, brush);
palette.setBrush(QPalette::Inactive, QPalette::Window, brush1);
palette.setBrush(QPalette::Disabled, QPalette::Base, brush1);
palette.setBrush(QPalette::Disabled, QPalette::Window, brush1);
ui.CancelButton->setPalette(palette);
then Make sure the autoFillBackground property of the widget is set to true.
hope this help!

wysota
27th February 2008, 07:53
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; ).

phillip_Qt
27th February 2008, 08:39
I ve solved the problem.

Thank you all .

phillip_Qt
27th February 2008, 09:08
HI all.
I ve changed the colour of window by usning the code


QPalette p( this->palette());
p.setColor( QPalette::Window, QColor(Qt::black));
this->setPalette(p);

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


if(QMainWindow::backgroundRole() == Qt::black)
{
QPalette p( this->palette());
p.setColor( QPalette::Window, QColor(Qt::gray));
this->setPalette(p);
}

But its not coming inside if loop.
Can any body help me.
thank you all.

wysota
27th February 2008, 09:13
Read what QWidget::backgroundRole does. It returns a role, not a colour.

jpn
27th February 2008, 09:13
QWidget::backroundRole() returns QPalette::ColorRole. It makes no sense to compare it to Qt::GlobalColor.



if (palette().color(Qt::Window) == Qt::black)
...

phillip_Qt
27th February 2008, 10:39
I tried to do like following.

if(palette.color(QPalette::Window) == Qt::black)
{
GrayColour();
}
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.

wysota
27th February 2008, 10:46
Have a boolean flag instead of checking the colour.

phillip_Qt
27th February 2008, 11:01
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.

wysota
27th February 2008, 11:12
You won't be able to change colours of other applications using Qt code.

phillip_Qt
27th February 2008, 11:23
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.

wysota
27th February 2008, 11:25
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.

phillip_Qt
27th February 2008, 11:41
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

wysota
27th February 2008, 11:58
Just call the function :)

phillip_Qt
27th February 2008, 12:05
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.

wysota
27th February 2008, 12:10
What kind of errors?

jpn
27th February 2008, 12:40
Can u plz tell me an example how to call Win32 API in Qt.
Qt is not a programming language but a library.


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() (http://msdn2.microsoft.com/en-us/library/ms724940(VS.85).aspx) docs...

phillip_Qt
27th February 2008, 13:19
What kind of errors?

mainwindow.cpp(33) : error C2065: 'COLOR_3DDKSHADOW' : undeclared identifier
.\mainwindow.cpp(34) : error C3861: 'RGB': identifier not found
.\mainwindow.cpp(35) : error C2065: 'm_ColourDay' : undeclared identifier
.\mainwindow.cpp(35) : error C3861: 'SetSysColors': identifier not found

Theses error.

jpn
27th February 2008, 13:19
mainwindow.cpp(33) : error C2065: 'COLOR_3DDKSHADOW' : undeclared identifier
.\mainwindow.cpp(34) : error C3861: 'RGB': identifier not found
.\mainwindow.cpp(35) : error C2065: 'm_ColourDay' : undeclared identifier
.\mainwindow.cpp(35) : error C3861: 'SetSysColors': identifier not found
As I said, read SetSysColors() (http://msdn2.microsoft.com/en-us/library/ms724940(VS.85).aspx) docs. Look at the bottom where it says "Header".

phillip_Qt
28th February 2008, 04:28
What kind of errors?

Im getting following errors.

.\mainwindow.cpp(33) : error C2065: 'COLOR_3DDKSHADOW' : undeclared identifier
.\mainwindow.cpp(35) : error C3861: 'SetSysColors': identifier not found

Thank you.

phillip_Qt
28th February 2008, 05:32
Qt is not a programming language but a library.


Perhaps you should read SetSysColors() (http://msdn2.microsoft.com/en-us/library/ms724940(VS.85).aspx) docs...


#ifdef OS_WINDOWS
quint32 m_ColourElement = COLOR_3DDKSHADOW;
quint32 m_ColourNight = qRgb(100, 100, 100);
SetSysColors(16, m_ColourElement, m_ColourNight);
#endif

Is it right?

jpn
28th February 2008, 06:25
Is it right?
No, it's not. First of all, where is OS_WINDOWS defined? Qt does not define such but something similar. Read QtGlobal docs what Qt defines. Secondly, you must include the header mentioned in SetSysColors() docs. Otherwise compiler doesn't know any SetSysColors() function. Thirdly, SetSysColors() doens't take parameters like that. Read SetSysColors() docs what type of parameters it takes.