QLabel设置边框和颜色:
label->setFrameShape (QFrame::Box);
label->setStyleSheet("border: 1px solid #ff0000");
设置字体大小和颜色:
ui.label是QLabel
ui.label_4->setText("some text");
//设置字号
QFont ft;
ft.setPointSize();
ui.label_4->setFont(ft);
//设置颜色
QPalette pa;
pa.setColor(QPalette::WindowText,Qt::red);
ui.label_4->setPalette(pa);
QTreeWidget中加入按钮:
void setItemWidget ( QTreeWidgetItem * item, int column, QWidget * widget );
怎么设置QTreeWidget的列宽?setSizeHint似乎不起作用 QTreeWidgetItem *headItem = watchTree->headerItem();
headItem->setSizeHint(,QSize(,));
headItem->setSizeHint(,QSize(,));
headItem->setText(,tr("GisRes"));
headItem->setText(,tr("period")); 是setLineWidth
为了方便,利用QLabel来形成QSplitter之间的间隙,但是无法精确控制宽度
setSizePolicy(QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
遍历树QTreeWidget:
int treeCount(QTreeWidget *tree, QTreeWidgetItem *parent = )
{
int count = ;
if (parent == ) {
int topCount = tree->topLevelItemCount();
for (int i = ; i < topCount; i++) {
QTreeWidgetItem *item = tree->topLevelItem(i);
if (item->isExpanded()) {
count += treeCount(tree, item);
}
}
count += topCount;
} else {
int childCount = parent->childCount();
for (int i = ; i < childCount; i++) {
QTreeWidgetItem *item = parent->child(i);
if (item->isExpanded()) {
count += treeCount(tree, item);
}
}
count += childCount;
}
return count;
}
And the usage: QTreeWidget tw;
// Add items
[..]
int visibleItemsCount = treeCount(&tw);