×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    24

    Re: coloring of QTableView

    Quote Originally Posted by divanov View Post
    Selection colours are actually coming from Fremantle default themes, but if you don't like them for some reason, you can make custom themes for your application.
    How can we have the rows/columns in Qtableiew/QListview/QTableWidget coloured in Fremantle ? Ive tried to implement a delegate to paint each row but it didnt seem to work fine. I would also like it to show a different color when selected.
    Can this be elaborated please as to how it can achieved ?

    this is my example, ive managed to color the text here , the Qt:Window color role didnt help in coloring the backround of the columns.

    Thanks for the time.

    Code:
    void TableViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                                      const QModelIndex &index) const
    {
        QPalette pal = option.palette;
        QStyleOptionViewItem  viewOption(option);
        if(index.column() == 1)
        {
            viewOption.palette.setColor(QPalette::Text, Qt::green);
        }
        else if (index.column() == 2)
        {
            viewOption.palette.setColor(QPalette::Text, Qt::red);
        }
        else if (index.column() == 3)
        {
            viewOption.palette.setColor(QPalette::Text, Qt::yellow);
        }
        else
        {
            viewOption.palette.setColor(QPalette::Text, Qt::white);
        }
    
        QStyledItemDelegate::paint(painter, viewOption, index);
    }

  2. #2
    Registered User
    Join Date
    Mar 2010
    Posts
    2

    Re: coloring of QTableView

    Dear rkurvakat,

    I am having a similar problem. I am using a QTableWidget and want some cells with different background colors. I tried the following:
    Code:
    ...
    item = QTableWidgetItem("")
    item.setBackground( QtGui.QBrush(QtCore.Qt.red) )
    # tw is of type QTableWidget 
    # tw.setStyle( QtGui.QWindowsStyle() )
    tw.setItem(0, 0, item)
    Using the Hildon-Style the cell does _NOT_ have the specified background color. But if I use a different style (here: QWindowsStyle), the background color is applied. I assume that this issue has to do something with the Hildon-Style? Is there a way to override this faulty(?) behaviour?

    Drawbacks of using a different style for the tablewidget:
    1. Inconsistent look&feel
    2. Kinetic Scrolling does not work


    Have a nice day,
    Dominik

    --
    Working environment: N900, PySide + Qt 4.6.2

  3. #3
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: coloring of QTableView

    Quote Originally Posted by bartenst View Post
    Code:
    item = QTableWidgetItem("")
    item.setBackground( QtGui.QBrush(QtCore.Qt.red) )
    # tw is of type QTableWidget 
    # tw.setStyle( QtGui.QWindowsStyle() )
    tw.setItem(0, 0, item)
    Alternatively you can do something like this:
    Code:
    model.setData(model.index(0, 0), QVariant(QBrush(Qt::red)), Qt::BackgroundRole);
    Quote Originally Posted by bartenst View Post
    Using the Hildon-Style the cell does _NOT_ have the specified background color. But if I use a different style (here: QWindowsStyle), the background color is applied. I assume that this issue has to do something with the Hildon-Style? Is there a way to override this faulty(?) behaviour?
    Maemo5 style is using Gtk pixmaps to draw background of the items, so one cannot really change the colour of background. The only way is to reimplement Maemo5 style and use the modified style in your application.

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    24

    Re: coloring of QTableView

    Quote Originally Posted by divanov View Post
    Alternatively you can do something like this:
    Code:
    model.setData(model.index(0, 0), QVariant(QBrush(Qt::red)), Qt::BackgroundRole);
    this doesnt work on Fremantle :-(
    failed to color the text.
    Last edited by rkurvakat; 2010-03-24 at 07:14.

  5. #5
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: coloring of QTableView

    Quote Originally Posted by rkurvakat View Post
    this doesnt work on Fremantle :-(
    failed to color the text.
    And in my previous post it's explained why.

  6. #6
    Registered User
    Join Date
    Mar 2010
    Posts
    2

    Re: coloring of QTableView

    One possibilty seems to be in using a QItemDelegate which "bypasses" the Hildon style:

    # delegate which overrides Hildon style
    delegate = QtGui.QItemDelegate()
    tablewidget.setItemDelegate(delegate)
    ...
    # colors are accepted
    item = QTableWidgetItem("")
    item.setBackground( QtGui.QBrush(QtCore.Qt.red) )

    Advantages:
    - Kinetic scrolling still works because the tablewidget still uses Hildon style

Similar Threads

  1. kinetic scrolling
    By stalep in forum Nokia N9
    Replies: 10
    Last Post: 2009-12-08, 12:41
  2. [moved] Text coloring
    By shahidur.rahman in forum Symbian User Interface
    Replies: 2
    Last Post: 2009-03-25, 08:24
  3. 860809 - syntax coloring
    By ilostmyid2 in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2007-11-01, 22:18
  4. all black text or failing syntax coloring
    By rpodraza in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2005-11-07, 15:47

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •