[英]Qt - how to customizing QTableWidget's checkbox
I've tried to set some style for check box for Qt. 我试图为Qt的复选框设置某种样式。 I've already knew that QtTableWidget has QCheckbox.
我已经知道QtTableWidget具有QCheckbox。 but problem is I have no idea how to set style for checkbox of QtTableWidget.
但是问题是我不知道如何设置QtTableWidget复选框的样式。
QTableWidgetItem *checkBoxItem = new QTableWidgetItem();
checkBoxItem->setCheckState(Qt::Unchecked);
table->setItem(row, column, checkBoxItem);
When I use setStyleSheet for checkBox : 当我将setStyleSheet用于checkBox时:
checkBoxItem->setStyleSheet("...");
I have an error: 'class QTableWidgetItem' has no member named 'setStyleSheet' 我有一个错误: “类QTableWidgetItem”没有名为“ setStyleSheet”的成员
Edited : I want to do some operation with checkBox. 编辑 :我想用复选框做一些操作。 Here is complete code for first QTableWidgetItem:
这是第一个QTableWidgetItem的完整代码:
for (int i = 0; i < 4; ++i)
m_tableWidget->setRowHeight(i, 3 * em);
QTableWidgetItem *item1 = new QTableWidgetItem(tr("Show Message Preview"));
if (CGlobalZone::m_showMsgPreview)
item1->setCheckState(Qt::Checked);
else
item1->setCheckState(Qt::Unchecked);
item1->setFlags(Qt::ItemIsEnabled);
m_tableWidget->setItem(0, 0, item1);
You can style the indicators with QAbstractItemView::indicator { ... } (eg QTableView::indicator:checked, QTableView::indicator:unchecked etc). 您可以使用QAbstractItemView :: indicator {...}设置样式(例如,QTableView :: indicator:checked,QTableView :: indicator:unchecked等)。
You can't apply style directly to the QTableItemWidget, but you can put a stylesheet on the QTableWidget itself or a parent of it. 您不能将样式直接应用于QTableItemWidget,但是可以将样式表放在QTableWidget本身或其父项上。
Assuming, you already have a table widget with at least one column and at least one row: 假设您已经有一个表窗口小部件,其中至少有一列和至少一行:
QCheckBox *cb = new QCheckBox(tr("Check me"));
cb->setStyleSheet("background-color: rgb(0, 85, 0);");
tableWidget->setCellWidget(0, 0, cb);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.