How to change color of paragraph border.
paragraph border color red
enter image description here
Although apache poi XWPF provides to set paragraph borders using XWPFParagraph.setBorder... methods - for ex. XWPFParagraph.html#setBorderLeft - it not provides setting border colors upto now. So we need using the underlaying low level org.openxmlformats.schemas.wordprocessingml.x2006.main.* classes.
Paragraph borders are set in paragraph properties (pPr). There are paragraph border (pBdr) elements having settings for left, top, right and bottom borders. Those left, top, right and bottom elements then have settings for line type (this is what apache poi provides already), line size and line color. The color is set as RGB-Hex.
Following example provides a method void setBorderLeftColor(XWPFParagraph paragraph, String rgb) to set left border color.
import java.io.FileOutputStream;
import org.apache.poi.xwpf.usermodel.*;
public class CreateWordParagraphBorderColor {
private static void setBorderLeftColor(XWPFParagraph paragraph, String rgb) {
if (paragraph.getCTP().getPPr() == null) return; // no paragraph properties = no borders
if (paragraph.getCTP().getPPr().getPBdr() == null) return; // no paragraph border
if (paragraph.getCTP().getPPr().getPBdr().getLeft() == null) return; // no left border
paragraph.getCTP().getPPr().getPBdr().getLeft().setColor(rgb);
}
public static void main(String[] args) throws Exception {
XWPFDocument document = new XWPFDocument();
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("Following paragraph with border left and border left color:");
paragraph = document.createParagraph();
paragraph.setBorderLeft(Borders.SINGLE);
setBorderLeftColor(paragraph, "FF0000");
run = paragraph.createRun();
run.setText("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.");
paragraph = document.createParagraph();
FileOutputStream out = new FileOutputStream("CreateWordParagraphBorderColor.docx");
document.write(out);
out.close();
document.close();
}
}
I am currently creating an application that helps analyse chat logs that have two participants. A bot and a customer.
My goal is to add a QTableWidget that has QTextEdit elements in it to my application's main window. The user can then select the text inside those QTextEdits. Once selected, the text background color of the selected text should be changed.
example:
Suspendisse suscipit, tellus ut varius aliquam, tortor enim placerat sem, sit amet porta eros tellus ultrices risus.
The user double clicks and selects "tellus ut varius" from the above text. The background color is now changed. If they select those words again, the change is reverted.
I am using this solution to add the QTextEdits to the QTableWidget:
How to put a TextEdit inside a cell in QTableWidget - Pyqt5?
The table is populated inside the following loop:
def populate_chat(self):
self.chat.setColumnCount(1)
self.chat.setRowCount(len(example_chat_list))
for idx, message in enumerate(example_chat_list):
oname1, oname2 = 'chat_bubble_bot', 'chat_bubble_customer'
if idx % 2 == 0:
combo = TextEdit(self, objectName=oname1)
else:
combo = TextEdit(self, objectName=oname2)
self.chat.setCellWidget(idx, 0, combo)
combo.setText(message)
combo.cursorPositionChanged.connect(self.test)
combo.textChanged.connect(
lambda idx=idx: self.chat.resizeRowToContents(idx))
self.chat.installEventFilter(self)
The goal is to have this function change the text background:
def test(self):
cursor = self.exampleelement.textCursor()
current_color = cursor.charFormat().background().color().rgb()
format = QTextCharFormat()
if cursor.hasSelection() and current_color != 4294901760:
format.setBackground(Qt.red)
else:
format.setBackground(QColor(70, 70, 70))
cursor.setCharFormat(format)
I am having trouble referring to the QTextEdit element (exampleelement in the code block) when calling the test function.
The chat bubbles for the participants are styled differently in a separate stylesheet where they are referred to by name. That is why I have kept the names of the objects different for the participants. I have also tried enumerating the names like chat_bubble_customer0. chat_bubble_customer1 and so on, but was still unsuccessful in transferring the name of the element over to the test function.
How do I lay out the following in SwiftUI?
The two circles are centre aligned horizontally along the blue line, and the top circle is vertically aligned with its rectangle along the green line, with the bottom circle vertically aligned with the bottom rectangle along the red line.
There’s no nested HStack/VStack structure that can describe this. We think the solution has something to do with custom alignment guides, but all of the examples we could find stop short of this level of complexity.
It feels like your best bet in this situation would be to use a LazyVGrid. There's a tendency to think of grids being used for collections where we might have long lists of items, but they also work for a known, finite number of children, so I think they'd work here.
In essence, you have two columns of items – both can be flexible to a degree, but it sounds like your column of rectangles needs to expand more. So you could start off by trying something like:
let columns = [
GridItem(.flexible(maximum: 120)),
GridItem(.flexible())
]
var body: some View {
LazyVGrid(columns: columns) {
// row 1, column 1
RoundedRectangle(cornerRadius: 10)
.frame(width: 100, height: 160)
// row 1, column 2
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tincidunt enim in iaculis tincidunt. Nunc vitae imperdiet dolor")
// row 2, column 1
Circle()
.frame(height: 100)
// row 2, column 2
Text("Integer vitae volutpat urna. Morbi vel pharetra dolor. Interdum et malesuada fames ac ante ipsum primis in faucibus. Mauris ornare a augue id cursus")
}
}
The code above gives you something like:
I've not had the opportunity to use grids in this way myself yet, so haven't played around with all the customisation they offer, but it does feel like this might be the best way to get you what you want without worrying about alignment guides or preferences.
I'm currently trying to dynamically create an animation and playing it to show text based on the length of the text and the set speed of characters per second.
What I'm trying to recreate in code is this animation:
So an animation with a property track on the label's property visible_characters with update mode on continuous and interpolation mode on linear
Structure of the scene is:
The script behind the DialogBox node:
extends Control
export(String, MULTILINE) var Text = ""
export(int) var CharactersPerSecond = 100
func _ready():
$Panel/Label.set_text(Text)
print($Panel/Label.get_text())
createAnimation()
$AnimationPlayer.play("show-text")
print("is playing " + str($AnimationPlayer.is_playing()))
print("current animation " + $AnimationPlayer.current_animation)
func createAnimation():
var animationLength = Text.length() / (CharactersPerSecond as float)
print(animationLength)
var animation = $AnimationPlayer.get_animation("show-text")
animation.clear()
var trackIdx = animation.add_track(Animation.TYPE_VALUE)
animation.track_set_path(trackIdx, "Panel/Label:visible_characters")
animation.track_set_interpolation_type(trackIdx,Animation.INTERPOLATION_LINEAR)
animation.value_track_set_update_mode(trackIdx, Animation.UPDATE_CONTINUOUS)
animation.track_insert_key(trackIdx, 0, 0)
animation.track_insert_key(trackIdx, animationLength, Text.length())
For testing purposes the text is being set in the editor using the exported Text variable and is some lorem ipsum.
What happens when I run the scene is that the Panel and Label get shown but no text is shown in the Label, it stays empty, but according the print statements the show-text animation is playing
The printed data in the output window is:
** Debug Process Started **
Godot Engine v3.1.2.stable.mono.official - https://godotengine.org
OpenGL ES 3.0 Renderer: AMD Radeon R7 200 Series
label text: Magnam consequatur vel alias earum accusantium. Nobis voluptatem voluptatem quaerat adipisci voluptas. Numquam id error earum consectetur veniam. Quaerat quibusdam quas sunt alias et blanditiis corporis. Cupiditate rem ut natus est molestiae quidem. Magnam consequatur vel alias earum accusantium. Nobis voluptatem voluptatem quaerat adipisci voluptas. Numquam id error earum consectetur veniam. Quaerat quibusdam quas sunt alias et blanditiis
animationlength: 4.44
is playing: True
current animation: show-text
** Debug Process Stopped **
so the problem was that i still needed to set the length of the animation
just inserting the keys wasn't enough
adding the following line after animation.clear() fixed it:
animation.set_length(animationLength)
I am having some trouble aligning results in Kableextra.
---
title: "Report test 1"
author: "Adam"
date: "May 9, 2019"
output: pdf_document
---
COLLEGE: College of Education
DEPARTMENT: Office of Assessment and Accreditation
SEMESTER: Fall 2018
SECTION 1: Please provide the mean and frequency distribution of the two required questions for all Traditional Delivery Courses. NOTE: The MEAN and N is required. The Frequency is optional.
x<-c(45,2,8,10,32,33)
y<-c(2,3,3,3,3,3)
EDLP_D.1<-cbind(x,y)
colnames(EDLP_D.1)<- c("Sheet", "Please indicate your level of satisfaction with the availability of the instructor outside the classroom. (In selecting your rating, consider the instructor's availability via established office hours, appointments, and opportunities for face-to-face interaction as well and as via telephones, e-mail, fax, and other means")
#function to compute values needed for table
vec_fun4 <- function(x,y){
Vec <-c(colnames(x[,y]),round(mean(x[[y]]),2),length(which(!is.na(x[,y]==F))),length(which(x[,y]==1)),length(which(x[,y]==2)),length(which(x[,y]==3)),length(which(x[,y]==4)))
return(Vec)
}
#Switch from long format to wide format
item2.1 <- as.data.frame(t(as.matrix(vec_fun4(EDLP_D.1,1))))
#Make table
library(kableExtra)
kable(item2.1,"latex" ,booktabs=T, align = "lcccccc", col.names=linebreak(c(' ','Mean','\\textit{N}' ,'Strongly\n Disagree','Disagree','Agree','Strongly\n Agree')),row.names = F,escape=F) %>%
column_spec(1, width = "20em" )
I would like to have the numeric values centered horizontally and vertically within their cells.
I have attached a copy of the table here
I don't have enough points to leave a comment. I am having the same issue, did you ever figure this out?
You can try this function to center the text:
centerText <- function(text){
paste0("\\multirow{1}{*}[0pt]{", text, "}")
}
However, this may mess up your formatting such as column width and text wrap like it did mine. Please let me know if you found a better solution.
My solution is replace few latex script
example:
```{r results='asis'}
library(kableExtra)
library(dplyr)
library(stringr)
kable(
data.frame(
'x1' = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reprehenderit voluptates ut quam delectus perferendis tempora, voluptas fuga deleniti asperiores ipsam ipsum nam animi sequi, nisi dicta, minus pariatur atque, nemo.',
'x2' = 11,
'x3' = 22,
'x4' = 33
),
# align = 'lccr',
# booktabs = T
col.names = c(' ','X2','X3' ,'X4'),
format = "latex"
) %>%
# column_spec(1, width = "20em") %>%
# column_spec(2:4, width = "5em") %>%
str_replace(
'(?<=\\\\begin\\{tabular\\}).+',
'{ >{\\\\raggedright\\\\arraybackslash}m{20em} >{\\\\centering\\\\arraybackslash}m{5em} >{\\\\centering\\\\arraybackslash}m{5em} >{\\\\raggedleft\\\\arraybackslash}m{5em} }'
) %>%
cat
```
ref: https://es.overleaf.com/learn/latex/Tables