PDA

View Full Version : QTreeWidget setCurrentItem difference height with the same setStyleSheet



trytoremeber963
11th January 2011, 01:51
case 0:
if i do not use any setCurrentItem function in the QTreeWidget,all the item are normal



QApplication a(argc, argv);

QString str1;
str1.append("uistyle.css");
QFile file(str1);

if(file.open(QFile::ReadOnly))
{
QString styleSheet = QObject::tr(file.readAll());
a.setStyleSheet(styleSheet);
file.close();
}

MainWindow w;
w.show();
return a.exec();




ui->setupUi(this);
//ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(0));
//ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(1));
//ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(2));


case 1:

in the main function i have used the setStyleSheet and use it before the mainwindow's construct function

if i use


ui->setupUi(this);
ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(0));
//ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(1));
//ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(2));

the first and the last item height are UNNormal but the second and the third is NORMAL
all the sub items are normal

case 2:

in the main function i have used the setStyleSheet and use it before the mainwindow's construct function



ui->setupUi(this);
ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(0));
ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(1));
//ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(2));

the first the second and the last item height are UNNormal but the third is NORMAL
all the sub items are normal

case 3
i change the order of mainwindow's construct function and the setStyleSheet func



QApplication a(argc, argv);

MainWindow w; //to here

QString str1;
str1.append("uistyle.css");
QFile file(str1);

if(file.open(QFile::ReadOnly))
{
QString styleSheet = QObject::tr(file.readAll());
a.setStyleSheet(styleSheet);
file.close();
}

//MainWindow w; //old position
w.show();
return a.exec();

all the item are normal

why? the attachment is follow

trytoremeber963
18th January 2011, 03:31
what about my question? Is there any body download the attached files and test ?

norobro
18th January 2011, 05:12
That's pretty strange. I tried setting the style sheet in the MainWindow ctor and it seems to work:
ui->treeWidget->setStyleSheet("::item { margin-top:2; margin-bottom:2; min-height:20;} "
"::item:selected:!active { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, "
"stop: 0 rgb(255,211,159), stop: 0.4 rgb(254,180,72), stop: 1 rgb(254,222,119));}"
"::item:selected:active { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, "
"stop: 0 rgb(66,180,255), stop: 1 rgb(0,152,255)); }"
"::item:hover { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, "
"stop: 0 rgb(247,235,224), stop: 1 rgb(255,211,159));}");
Didn't get any warnings but maybe there is a problem parsing your css file.

Edit: I quit reading and tried your code before getting to case 3.