I want to add text (at the beginning of a row) and an image at the end of the row.
I can set the text but how to set an image at the end of the row item in QTreeWidgetItem?
Just set for example two columns in QTreeWidget and then set text in first one and icon in second one:
QTreeWidgetItem *newItem = new QTreeWidgetItem;
newItem->setText(0, "Something");
newItem->setIcon(1, QIcon("Path to your icon"));
myTreeWidget->addTopLeveItem(newItem);
Or instread of setting icon you can just set foreground:
newItem->setForeground(QBrush(QPixmap("Path to your image")));
which may be better for your problem.
Related
How can I set vertical align to the text on PHPExcel
I tried with
$phpExcelObject->getActiveSheet()->getStyle('B2:B5')->getAlignment()->setReadorder(
PHPExcel_Style_Alignment::READORDER_RTL
);
But it didn't work.
I actually have:
THE TEXT
But I want
T
H
E
T
E
X
T
Like the image.
It's not vertical alignment that you want to look at: vertical alignment is whether the content should be at the top/centre/bottom of a cell; nor RTL, which is Right-to-Left. You could perhaps look at text rotation, but that rotates the orientation of the text.
You'll always need to set the row height to automatic and enable wrapping.
$objPHPExcel->getActiveSheet()
->getRowDimension(12)
->setRowHeight(-1);
$objPHPExcel->getActiveSheet()
->getStyle('A1')
->getAlignment()->setWrapText(true);
so that it will expand to the actual size of your text.
Then an option would be to add a new line character after every character in your string before setting the cell value:
$value = "THE TEXT";
$objPHPExcel->getActiveSheet()
->setCellValue('A1', implode("\n", str_split($value)));
I See what your problem is,
I have solution for you , you still using getAlignment()->setWrapText(true); on your code, but you can add variable that fill is "\n" for every value you want it.
For Example :
$n= "\n";
$objPHPExcel->getActiveSheet()->setCellValue('A','T'.$n.'E'.$n.'S'.$n.'T');
$objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setWrapText(true);
result's as bellow:
T
E
S
T
Hope this answer can help you.
I have QTreeWidget with two columns. The first column is the text, and the second is QPushButton. I can not specify the size of buttons and the size of the second column. When you try to set the size of the column of content, the second column disappears. How to change the width of the second column?
tree_widget_->setColumnCount(2);
tree_widget_->header()->resizeSection(1, 10);
tree_widget_->header()->setStretchLastSection(false);
tree_widget_->header()->setResizeMode(0,QHeaderView::Stretch);
tree_widget_->topLevelItem(4)->addChild( wiop = new QTreeWidgetItem(QStringList() << QString( "Расстояние: %1 км" ).arg( range ) ) );
tree_widget_->setItemWidget(tree_widget_->topLevelItem(4)->child(0),1,range_plot_button_ = new QPushButton("График",tree_widget_));
range_plot_button_->resize(10,10);
tree_widget_->setColumnWidth(1, 10) should do what you wanted.
When you assign QPushButton to QTreeWidget as a top level item the QTreeWidget object usualy assigned as a parent of this button, so all geometry of that button is handled by it's parent.
Take a look at docs.
If you want your push button to have it's own geometry with layouts (within column) you can make blank widget, set it to TreeWidget as an item and make your push button to be a child of that blank widget with all conveniences of layouts in Qt.
I try setColumnWidth, but it is not work.
Later I try tree_widget_->header()->setResizeMode(1,QHeaderView::ResizeToContents);
and it is work!
I want to specify spacing between two elements within JavaFX Buttons, Here is the Code :
ImageView fiv = new ImageView(new Image("/modified/map.png"));
fiv.setFitHeight(20);
fiv.setPreserveRatio(true);
Button cr = new Button( "Crop", fiv);
Here I want to Specify Spacing Between "Crop" and fiv, How can i do this ?
Use graphicTextGap property of the button.
the large glyph all on the left . small glyph on the right with vertical allignment.
all the button are generated on the code.
this is my code using c# for winform showing
RibbonPageGroup pagGroup = new RibbonPageGroup();
BarButtonItem barButtonItem = new BarButtonItem();
pagGroup.ItemLinks.Add(barButtonItem);e
You should add your bar item links into PageGroup one by one. For small items use the BarItemLink.BeginGroup property to separate all the next items into button group:
// ribbonPageGroup1
ribbonPageGroup.ItemLinks.Add(barButtonItem1);
ribbonPageGroup.ItemLinks.Add(barButtonItem2);
ribbonPageGroup.ItemLinks.Add(barButtonItem3, true); // begin group
ribbonPageGroup.ItemLinks.Add(barButtonItem4);
ribbonPageGroup.ItemLinks.Add(barButtonItem4);
Use the BarItem.RibbonStyle propety to specify display options for specific bar items:
barButtonItem3.RibbonStyle = DevExpress.XtraBars.Ribbon.RibbonItemStyles.SmallWithText;
I want to change color of the row with NULL items (I didn't do setData() or setItem()) in QTableWidget. How to do this?
To have full control over the items, I would just drop in an item, and then set the background color:
Fill the row with QTableWidgetItem's and then you can change the background color.
QTableWidgetItem *newItem = new QTableWidgetItem("");
tableWidget->setItem(row, column, newItem);
QColor color( Qt::red );
tableWidget->item( row, column )->setBackgroundColor( color );
That is the main way that I have formatted any cells in the past.
QStyleSheets
In the documentation for QStyleSheets, QTableView and QTableWidget share the same kind of properties:
http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-qtableview
http://qt-project.org/doc/qt-4.8/stylesheet-reference.html#alternate-background-color-prop
http://qt-project.org/doc/qt-4.8/stylesheet-reference.html#item-sub
It should work with the table and rows, even if it isn't full of items.
Hope that helps!