Results 1 to 3 of 3

Thread: QTreeWidget setCurrentItem difference height with the same setStyleSheet

  1. #1
    Join Date
    Jun 2008
    Posts
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QTreeWidget setCurrentItem difference height with the same setStyleSheet

    case 0:
    if i do not use any setCurrentItem function in the QTreeWidget,all the item are normal

    Qt Code:
    1. QApplication a(argc, argv);
    2.  
    3. QString str1;
    4. str1.append("uistyle.css");
    5. QFile file(str1);
    6.  
    7. if(file.open(QFile::ReadOnly))
    8. {
    9. QString styleSheet = QObject::tr(file.readAll());
    10. a.setStyleSheet(styleSheet);
    11. file.close();
    12. }
    13.  
    14. MainWindow w;
    15. w.show();
    16. return a.exec();
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. ui->setupUi(this);
    2. //ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(0));
    3. //ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(1));
    4. //ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(2));
    To copy to clipboard, switch view to plain text mode 

    case 1:

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

    if i use
    Qt Code:
    1. ui->setupUi(this);
    2. ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(0));
    3. //ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(1));
    4. //ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(2));
    To copy to clipboard, switch view to plain text mode 
    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

    Qt Code:
    1. ui->setupUi(this);
    2. ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(0));
    3. ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(1));
    4. //ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(2));
    To copy to clipboard, switch view to plain text mode 
    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

    Qt Code:
    1. QApplication a(argc, argv);
    2.  
    3. MainWindow w; //to here
    4.  
    5. QString str1;
    6. str1.append("uistyle.css");
    7. QFile file(str1);
    8.  
    9. if(file.open(QFile::ReadOnly))
    10. {
    11. QString styleSheet = QObject::tr(file.readAll());
    12. a.setStyleSheet(styleSheet);
    13. file.close();
    14. }
    15.  
    16. //MainWindow w; //old position
    17. w.show();
    18. return a.exec();
    To copy to clipboard, switch view to plain text mode 
    all the item are normal

    why? the attachment is follow
    Attached Files Attached Files
    Last edited by trytoremeber963; 11th January 2011 at 02:02.

  2. #2
    Join Date
    Jun 2008
    Posts
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget setCurrentItem difference height with the same setStyleSheet

    what about my question? Is there any body download the attached files and test ?

  3. #3
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QTreeWidget setCurrentItem difference height with the same setStyleSheet

    That's pretty strange. I tried setting the style sheet in the MainWindow ctor and it seems to work:
    Qt Code:
    1. ui->treeWidget->setStyleSheet("::item { margin-top:2; margin-bottom:2; min-height:20;} "
    2. "::item:selected:!active { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, "
    3. "stop: 0 rgb(255,211,159), stop: 0.4 rgb(254,180,72), stop: 1 rgb(254,222,119));}"
    4. "::item:selected:active { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, "
    5. "stop: 0 rgb(66,180,255), stop: 1 rgb(0,152,255)); }"
    6. "::item:hover { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, "
    7. "stop: 0 rgb(247,235,224), stop: 1 rgb(255,211,159));}");
    To copy to clipboard, switch view to plain text mode 
    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.
    Last edited by norobro; 18th January 2011 at 05:38. Reason: added comment

Similar Threads

  1. QToolButton & setStyleSheet
    By kavinsiva in forum Newbie
    Replies: 1
    Last Post: 3rd June 2010, 14:52
  2. Replies: 1
    Last Post: 21st November 2008, 16:06
  3. Problem to setstylesheet
    By phillip_Qt in forum Qt Programming
    Replies: 3
    Last Post: 14th April 2008, 06:57
  4. using setStyleSheet
    By Weilor in forum Qt Programming
    Replies: 11
    Last Post: 18th January 2008, 13:41
  5. Replies: 2
    Last Post: 6th April 2006, 08:21

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.