Skip to content
QtWS25 Last Chance
  • Checkbox and combobox in table cell

    Moved Unsolved Qt for Python checkbox table
    3
    0 Votes
    3 Posts
    562 Views
    jeremy_kJ
    @Pl45m4 said in Checkbox and combobox in table cell: @Gazi That is what delegates are for https://doc.qt.io/qt-6/qitemdelegate.html#details Assign the delegates where you have your boolean values The standard styled delegate for widget views handles Qt::CheckStateRole. The link doesn't go directly to the role. @Gazi At over 300 lines, this code snippet is waa[...]aay too large for a reasonable question. Please limit examples to the minimum required to explain the problem.
  • Checkbox Dimension

    Unsolved Qt Design Studio checkbox qtdesign c++
    2
    0 Votes
    2 Posts
    562 Views
    T
    The size of the CheckBox is on controlled by the style/theme. See: https://doc.qt.io/qt-6/qtquickcontrols2-styles.html
  • 0 Votes
    2 Posts
    616 Views
    M
    Problem solved by calling chekbox.forceActiveFocus(Qt.TabFocusReason)
  • onCheckedChanged vs onCheckStateChanged

    Solved General and Desktop checkbox
    3
    1 Votes
    3 Posts
    1k Views
    C
    @KroMignon Thanks
  • 0 Votes
    20 Posts
    10k Views
    D
    Hey Got a follow up question in regards to styling... How can I get QComboBox focus indicator/rect ? So that I can set correct color for the outline of comboBox to paint? I tried using QRect r = QApplication::style()->subElementRect(QStyle::SE_ComboBoxLayoutItem, &option, mWidgetList[ComboBox]); and QRect r = QApplication::style()->subElementRect(QStyle::SE_ComboBoxFocusRect, &option, mWidgetList[ComboBox]); But neither return correct rect to use as paint target... Only the large square one around item in tree view. Any hints? Same for QPushButton, and pretty much any button/combo like widget I think o.O TIA.
  • 0 Votes
    6 Posts
    3k Views
    Christian EhrlicherC
    I'm sorry but I don't think will compile. Please provide a minimal, compilable example which shows your problem. E.g int main (int argc, char **argv) { QApplication app(argc, argv); QTreeWidget treeWidget; QTreeWidgetItem *cities = new QTreeWidgetItem(&treeWidget); cities->setText(0, "Cities"); treeWidget.show(); return app.exec(); } See http://doc.qt.io/qt-5/qtreewidgetitem.html#details
  • 0 Votes
    4 Posts
    11k Views
    VRoninV
    @MATTK said in Configuring checkbox when using QTreeWidget: is this a bug or a known issue from Qt Designer? No, it's 100% intended behaviour. the condition is checked here You have 2 options: set the Qt::CheckStateRole for the indexes you want to have a checkbox. In your widget constructor you'd call something like setUnchecked(ui->treeWidget->model()); void setUnchecked(QAbstractItemModel* model, const QModelIndex& parent = QModelIndex()){ if(!model) return; for(int i=0, maxRow=model->rowCount(parent);i<maxRow;++i){ for(int j=0, maxCol=model->columnCount(parent);j<maxCol;++j){ const QModelIndex currIdx = model->index(i,j,parent); model->setData(currIdx,Qt::Unchecked,Qt::CheckStateRole); if(model->hasChildren(currIdx)) setUnchecked(model,currIdx); } } } subclass the delegate to check the flag instead of Qt::CheckStateRole and call something like ui->treeWidget->setItemDelegate(new CheckFlagDelegate(this)); in your widget constructor class CheckFlagDelegate : public QStyledItemDelegate{ Q_OBJECT Q_DISABLE_COPY(CheckFlagDelegate) public: explicit CheckFlagDelegate(QObject* parent = Q_NULLPTR) : QStyledItemDelegate(parent){} protected: void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const Q_DECL_OVERRIDE{ QStyledItemDelegate::initStyleOption(option,index); if(index.model()->flags(index) & Qt::ItemIsUserCheckable) option->features |= QStyleOptionViewItem::HasCheckIndicator; } }; Since the functionality is defined in a QObject (the delegate) and not in a QWidget this is not something designer can and probably ever will manage
  • CheckBox to QInputDialog..?

    Unsolved General and Desktop qinputdialog checkbox dialog
    2
    0 Votes
    2 Posts
    2k Views
    raven-worxR
    @Rohith no it's not. You would have to implement your custom QDialog subclass. Which shouldn't be much of an effort.
  • Dodanie kolumny z checkboxem do QTableView

    Unsolved Polish qsqlquerymodel checkbox qtableview
    2
    0 Votes
    2 Posts
    1k Views
    Chris KawaC
    Można użyć modelu proxy, który będzie interpretował jakieś dane (np. "0" i "1") jako checkbox, np. class MyProxy : public QIdentityProxyModel { public: MyProxy(QObject* parent) : QIdentityProxyModel(parent) {} QVariant data(const QModelIndex& index, int role) const override { if (role == Qt::CheckStateRole && index.column() == 0) { QString str_value = QIdentityProxyModel::data(index, Qt::DisplayRole).toString(); return (str_value == "1") ? Qt::Checked : Qt::Unchecked; } return QIdentityProxyModel::data(index, role); } bool setData(const QModelIndex& index, const QVariant& value, int role) override { if (role == Qt::CheckStateRole && index.column() == 0) { QString str_value = (value.toInt() == Qt::Checked) ? "1" : "0"; return QIdentityProxyModel::setData(index, str_value, Qt::EditRole); } else return QIdentityProxyModel::setData(index, value, role); } Qt::ItemFlags flags(const QModelIndex& index) const override { Qt::ItemFlags f = QIdentityProxyModel::flags(index); if (index.column() == 0) f |= Qt::ItemIsUserCheckable; return f; } }; oczywiście numer kolumny i dane rozpoznawane jako "zaznaczony" można sobie dostosować. Takiego modelu można użyć potem tak: QSqlTableModel* model = new QSqlTableModel(parent, database); MyProxy* proxy = new MyProxy(parent); proxy->setSourceModel(model); tableView->setModel(proxy);
  • TableView with CheckBox in header

    Solved QML and Qt Quick qml tablview checkbox
    6
    0 Votes
    6 Posts
    4k Views
    P
    @medyakovvit Yeah, that woks. Thanks :)
  • ComboBox Of CheckBoxes not working in Qt5

    Unsolved General and Desktop combobox model checkbox
    5
    0 Votes
    5 Posts
    3k Views
    Fahad Al-SaidiF
    @Devopia53 Thanks, the checkboxes are displayed at least but selection by mouse is very difficult. I don't know why. UPDATE I comment out li->flags() and things works fine.
  • checkbox column in tableview

    Unsolved General and Desktop checkbox delegate column
    2
    0 Votes
    2 Posts
    3k Views
    No one has replied
  • 0 Votes
    3 Posts
    13k Views
    mrjjM
    @maximo Hi It creates a new Header that draws a check box image on itself since its not possible to insert a real widget. It then response to mouse press to make the image work as a real check box. it checks with if (logicalIndex == 0) so I think it only paints this in first column.
  • 0 Votes
    1 Posts
    1k Views
    No one has replied
  • 0 Votes
    9 Posts
    13k Views
    A
    @Brad-M I made it in Designer. I double checked the id box. It has ckbox. Sorry I am just now getting back to you. It has been busy at work this week.
  • 0 Votes
    3 Posts
    3k Views
    V
    Hi try to use Binding to your CheckBox: Binding { target: checkbox property: 'checked' value: checkboxenable } where checkboxenable is role in your model
  • 0 Votes
    2 Posts
    2k Views
    SGaistS
    Hi, Nothing really wrong, QWidget using style sheets are rendered by a special style. With style sheets you can customize things that might not be done with the native style.
  • 0 Votes
    15 Posts
    6k Views
    ealioneE
    No there is not at the moment. But as I said earlier this was based on some code from here. I tested it too, and if you try to add checkboxes just in the way I have done in the code above and compile, you can clearly see what I am talking about. Just make sure you browse to a folder that contains only images of the dimensions I specified.
  • 0 Votes
    5 Posts
    4k Views
    I
    use this QComboBox QAbstractItemView { selection-background-color: lightgray; } QAbstractItemView::indicator { background-color: rgb(0, 255, 0); width :20; height :20; } QAbstractItemView::indicator:checked { background-color: rgb(255, 170, 0); }
  • 0 Votes
    2 Posts
    1k Views
    SGaistS
    Hi and welcome to devnet, Since you are painting things yourself, you would also need to handle the mouse interaction yourself. Painting a QCheckBox is not the same has having an actual checkbox widget.