Alternating row colors in mac and linux



  • I want to alternate the colors of a QComboBox. In Windows I have no problem using the view().setAlternatingRowColors(true) function. In Linux and Mac it looks like impossible. I tried also using style sheet (see following code) but I had the same kind of results (all rows with the same background color). Can you explain me what is my error?

    @#include <QtGui/QApplication>
    #include <QComboBox>
    #include <QAbstractItemView>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    a.setStyleSheet("QComboBox QAbstractItemView{qproperty-alternatingRowColors: true;alternate-background-color: blue;background: red;}");
    QComboBox b;
    b.addItem("MM_NONE");
    b.addItem("MM_VERT");
    b.addItem("MM_FACE");
    b.addItem("MM_EDGE");
    bool tt = false;
    tt = b.view()->alternatingRowColors();
    b.show();
    return a.exec();
    }@



  • This seems to work on my Mac...

    @
    #include <QtGui/QApplication>
    #include "MainWindow.h"

    int main(int argc, char *argv[])
    {
    #ifdef Q_WS_WIN
    // Winduhs
    QApplication::setStyle("windowsvista");
    #else
    // Mac
    QApplication::setDesktopSettingsAware(false);
    QApplication::setColorSpec(QApplication::ManyColor);
    QApplication::setStyle("plastique");
    #endif

    QApplication a(argc, argv);

    a.setStyleSheet("QComboBox QAbstractItemView{qproperty-alternatingRowColors: true;alternate-background-color: lightGray;background: white;}");

    MainWindow w;
    w.show();

    return a.exec();
    }
    @



  • I have had the same problem(?), with GTK and Qt. The reason for this behavior is the theme the computer is using - it may not have alternate colors for rows, even if you request it. This is the case at least with Linux Mint I use, no program has alternating row colors in their list boxes.

    So, basically, you should do nothing, as it is generally good to obey user's settings. If you want them visible, you should change your personal desktop settings.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.