PDA

View Full Version : stylesheet question



gt.beta2
29th January 2009, 15:55
Hi,
Imagine i have a Dialog (myDialog) with 3 QLineEdit objects: lineEdit1, lineEdit2, lineEdit3. I am using QtDesiner so i have 4 files:

main.cpp
myDialog.h
myDialog.cpp
myDialog.ui


If i want to apply a red color to the background off all lineEdits in the application e use, in main.cpp the following:

app.setStyleSheet("QLineEdit { background-color: red }");

Now supose i want to apply other stylesheet color as the Dialog level. Where showld i place the code:

myDialog->setStyleSheet("QLineEdit { background-color: yellow }");
?
Thanks

aamer4yu
30th January 2009, 11:52
myDialog->setStyleSheet(" background-color: yellow "); should do it.
When specifying QLineEdit in that line, it means for all line edits in that dialog ;)

gt.beta2
30th January 2009, 16:11
humm ... i don't think i explained myself well.
Imagine this situation:

#include <QApplication>

#include "Dialog_1.h"
#include "Dialog_2.h"

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

//apply stylesheet at application level
app.setStyleSheet("QLineEdit { background-color: red }");

Dialog_1 *dialog1 = new Dialog_1;
Dialog_2 *dialog2 = new Dialog_2;
dialog1->show();
dialog2->show();
return app.exec();
}

Both dialogs will show the color red on all lineedits, right?
Now imagine that dialog 2 is meant to be an exception, and i can not edit main.cpp.
Where in the .h, .ui or .cpp do i apply the overriding stylesheet?
Hope this makes any sense :o

jpn
30th January 2009, 17:27
Use selectors, for example object name.