Results 1 to 6 of 6

Thread: QStyledItemDelegate - style sheet not working

  1. #1
    Join Date
    Sep 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QStyledItemDelegate - style sheet not working

    Hi there,

    I want to put QProgressBar into tableview, so i made my own delegate based on QStyledItemDelegate. In documentation of QStyledItemDelegate its written, that it should work with defined style sheet. I defined it in designer. It works for progressbar, that is not in list, but i doesn't work in qtableview.
    My enviroment: QT 4.6.3 on Kubuntu 10.04 amd64.

    Anyone knows solution on that?

    code of my paint function:
    Qt Code:
    1. void CProgressbarDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    2. {
    3. QStyleOptionProgressBar oProgressBarStyle;
    4. oProgressBarStyle.rect = option.rect;
    5. oProgressBarStyle.minimum = 0;
    6. oProgressBarStyle.maximum = 100;
    7. oProgressBarStyle.progress = index.model()->data(index, Qt::DisplayRole).toInt();
    8. oProgressBarStyle.textAlignment = Qt::AlignHCenter;
    9. oProgressBarStyle.textVisible = true;
    10. oProgressBarStyle.text = QString::number(oProgressBarStyle.progress)+"%";
    11.  
    12. QApplication::style()->drawControl(QStyle::CE_ProgressBar, &oProgressBarStyle, painter, m_pWidget);
    13. }
    To copy to clipboard, switch view to plain text mode 

    m_pWidget was QTableView pointer and MainWindow pointer, even without QWidget it doesn't work.

  2. #2
    Join Date
    Sep 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QStyledItemDelegate - style sheet not working

    no one had similar problem?

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QStyledItemDelegate - style sheet not working

    How does your style sheet look like? Are your sure it matches your widget?

  4. #4
    Join Date
    Sep 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QStyledItemDelegate - style sheet not working

    It works for progress bar that is not in list. Thats my style sheet:
    Qt Code:
    1. {
    2. background-color: rgb(95, 95, 95);
    3. color: white;
    4. text-align: center;
    5. }
    6.  
    7. {
    8. background-color: rgb(155, 211, 70);
    9. color: white;
    10. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jul 2009
    Posts
    74
    Thanks
    2
    Thanked 6 Times in 6 Posts

    Default Re: QStyledItemDelegate - style sheet not working

    I have the same problem...
    any idea?
    thank you

  6. #6
    Join Date
    Nov 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows Maemo/MeeGo

    Default Re: QStyledItemDelegate - style sheet not working

    I am wondering about the same thing when trying this with a QSlider. Qt 4.7.0 on Windows machine. using plastique style and a custom style sheet for the sliders. I set the stylesheet using qApp->setStyleSheet(..) in the main application and

    void MySliderDelegate:aint(QPainter *painter, const QStyleOptionViewItem &option,
    const QModelIndex &index) const
    {
    ... some init code ...
    qApp->style()->drawComplexControl(QStyle::CC_Slider, &sliderOption, painter);
    }

    Regular sliders inside any widget use the stylesheet, the delegate doesn't.

Similar Threads

  1. Problems with Gradient style used through Style sheet on ARM platform
    By puneet.narsapur in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 25th January 2010, 12:48
  2. Inherited Style Sheet
    By johnmauer in forum Qt Programming
    Replies: 1
    Last Post: 2nd January 2010, 21:07
  3. How to set Style sheet for QCalendarWidget?
    By nifei in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2009, 22:36
  4. Qt 4.3 Style sheet, new features
    By Angelo Moriconi in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2007, 15:22
  5. How to use style sheet
    By safknw in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2006, 13:05

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.