QWidget *CustCharacteristicDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & /*style*/, const QModelIndex & index) const { if(index.column()!=1) return 0; QModelIndex idx = index.sibling(index.row(), 0); q.prepare("SELECT charass_value" " FROM charass, char" " WHERE ((charass_char_id=char_id)" " AND (charass_target_type='CT')" " AND (charass_target_id=:custtype_id)" " AND (char_id=:char_id) );"); q.bindValue(":char_id", idx.model()->data(idx, Qt::UserRole)); q.bindValue(":custtype_id", index.model()->data(index, Qt::UserRole)); q.exec(); QComboBox *editor = new QComboBox(parent); editor->setEditable(true); #ifdef Q_WS_MAC QFont boxfont = editor->font(); boxfont.setPointSize((boxfont.pointSize() == -1) ? boxfont.pixelSize() - 3 : boxfont.pointSize() - 3); editor->setFont(boxfont); #endif while(q.next()) editor->addItem(q.value("charass_value").toString()); editor->installEventFilter(const_cast<CustCharacteristicDelegate*>(this)); return editor; }
QWidget *CustCharacteristicDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & /*style*/, const QModelIndex & index) const { if(index.column()!=1) return 0; QModelIndex idx = index.sibling(index.row(), 0); characteristic::Type chartype = characteristic::Text; // Determine what type we have XSqlQuery qry; qry.prepare("SELECT char_id, char_type " "FROM char " "WHERE (char_id=:char_id); "); qry.bindValue(":char_id", idx.model()->data(idx, Qt::UserRole)); qry.exec(); if (qry.first()) chartype = (characteristic::Type)qry.value("char_type").toInt(); if (chartype == characteristic::Text || chartype == characteristic::List) { q.prepare("SELECT charass_value " "FROM char, charass " " LEFT OUTER JOIN charopt ON ((charopt_char_id=charass_char_id) " " AND (charopt_value=charass_value)) " "WHERE ((charass_char_id=char_id)" " AND (charass_target_type='CT')" " AND (charass_target_id=:custtype_id)" " AND (char_id=:char_id) ) " "ORDER BY COALESCE(charopt_order,0), charass_value;"); q.bindValue(":char_id", idx.model()->data(idx, Qt::UserRole)); q.bindValue(":custtype_id", index.model()->data(index, Xt::IdRole)); q.exec(); QComboBox *editor = new QComboBox(parent); editor->setEditable(chartype == characteristic::Text); #ifdef Q_WS_MAC QFont boxfont = editor->font(); boxfont.setPointSize((boxfont.pointSize() == -1) ? boxfont.pixelSize() - 3 : boxfont.pointSize() - 3); editor->setFont(boxfont); #endif while(q.next()) editor->addItem(q.value("charass_value").toString()); editor->installEventFilter(const_cast<CustCharacteristicDelegate*>(this)); return editor; } else if (chartype == characteristic::Date) { DLineEdit *editor = new DLineEdit(parent); return editor; } return 0; }
void QtHelpers::GenAdjustWidgetAppearanceToOS(QWidget *rootWidget) { if (rootWidget == NULL) return; QObject *child = NULL; QObjectList Containers; QObject *container = NULL; QStringList DoNotAffect; // Make an exception list (Objects not to be affected) DoNotAffect.append("aboutTitleLabel"); // about Dialog DoNotAffect.append("aboutVersionLabel"); // about Dialog DoNotAffect.append("aboutCopyrightLabel"); // about Dialog DoNotAffect.append("aboutUrlLabel"); // about Dialog DoNotAffect.append("aboutLicenseLabel"); // about Dialog // Set sizes according to OS: #ifdef __APPLE__ int ButtonHeight = 35; int cmbxHeight = 30; QFont cntrlFont("Myriad Pro", 14); QFont txtFont("Myriad Pro", 14); #elif _WIN32 // Win XP/7 int ButtonHeight = 24; int cmbxHeight = 20; QFont cntrlFont("MS Shell Dlg 2", 8); QFont txtFont("MS Shell Dlg 2", 8); #else int ButtonHeight = 24; int cmbxHeight = 24; QFont cntrlFont("Ubuntu Condensed", 10); QFont txtFont("Ubuntu", 10); #endif // Append root to containers Containers.append(rootWidget); while (!Containers.isEmpty()) { container = Containers.takeFirst(); if (container != NULL) { for (int ChIdx=0; ChIdx < container->children().size(); ChIdx++) { child = container->children()[ChIdx]; if (!child->isWidgetType() || DoNotAffect.contains(child->objectName())) continue; // Append containers to Stack for recursion if (child->children().size() > 0) Containers.append(child); else { // Cast child object to button and label // (if the object is not of the correct type, it will be NULL) QPushButton *button = qobject_cast<QPushButton *>(child); QLabel *label = qobject_cast<QLabel *>(child); QComboBox *cmbx = qobject_cast<QComboBox *>(child); QLineEdit *ln = qobject_cast<QLineEdit *>(child); QTreeWidget *tree = qobject_cast<QTreeWidget *>(child); QPlainTextEdit *plain = qobject_cast<QPlainTextEdit *>(child); QCheckBox *check = qobject_cast<QCheckBox *>(child); if (button != NULL) { button->setMinimumHeight(ButtonHeight); // Win button->setMaximumHeight(ButtonHeight); // Win button->setFont(cntrlFont); } else if (cmbx != NULL) { cmbx->setFont(cntrlFont); cmbx->setMaximumHeight(cmbxHeight); } else if (label != NULL) label->setFont(txtFont); else if (ln != NULL) ln->setFont(txtFont); else if (tree != NULL) { tree->header()->setFont(txtFont); } else if (plain != NULL) plain->setFont(txtFont); else if (check != NULL) check->setFont(txtFont); } } } } }