小编jac*_*ack的帖子

tableview中的checkbox和itemdelegate

我正在做一个继承自QitemDelegate的CheckBox的实现,把它放到QTableView中.

问题是我在插入时向左冲,我需要它居中.

据我所知,负责Paint的方法.我写的如下:

void CheckBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
bool checkValue;

QStyleOptionButton BtnStyle;
BtnStyle.state = QStyle::State_Enabled;

if(index.model()->data(index, Qt::DisplayRole).toBool() == true)
{
BtnStyle.state |= QStyle::State_On;
checkValue = true;
}else{
BtnStyle.state |= QStyle::State_Off;
checkValue = false;
}


BtnStyle.direction = QApplication::layoutDirection();
BtnStyle.rect = option.rect;
QApplication::style()->drawControl(QStyle::CE_CheckBox,&BtnStyle,painter );
QApplication::style()->drawControl(QStyle::CE_CheckBox,&BtnStyle,painter );
}
Run Code Online (Sandbox Code Playgroud)

什么缺少出现居中?

所以我有委托:

.H

class BooleanWidget : public QWidget
{
    Q_OBJECT
    QCheckBox * checkBox;

    public:
    BooleanWidget(QWidget * parent = 0)
    {
        checkBox = new QCheckBox(this);
        QHBoxLayout * layout = new …
Run Code Online (Sandbox Code Playgroud)

qt qtableview qitemdelegate qcheckbox

5
推荐指数
2
解决办法
1万
查看次数

同步Qt中的滚动条

我有各2 graphicsview与单独的滚动条,因为在看到图像.我想知道我是如何同步的,所以另一个移动也是如此.

谢谢

qt qgraphicsview

3
推荐指数
1
解决办法
1257
查看次数

标签 统计

qt ×2

qcheckbox ×1

qgraphicsview ×1

qitemdelegate ×1

qtableview ×1