How to remove space between radiobuttons in pyqt5 - python

How To Remove Padding Between Male And Female RadioButtons?
Here's My Code :
def UiComponents(self):
self.gridbox=QGridLayout()
self.label=QLabel("What's Your Gender?")
self.r1=QRadioButton("Male")
self.r2=QRadioButton("Female")
self.r3=QRadioButton("Rather Not To Say")
self.button=QPushButton("Submit")
self.gridbox.addWidget(self.label,0,0)
self.gridbox.addWidget(self.r1,1,0)
self.gridbox.addWidget(self.r2,1,1)
self.gridbox.addWidget(self.r3,1,2)
self.gridbox.addWidget(self.button,2,0)
self.setLayout(self.gridbox)
self.show()

Try changing spacing attribute at setStyleSheet() method like so
r1.setStyleSheet("""
QRadioButton {
spacing : 20px; #(<- example value)
}
""")

QGridLayout works like html table - you got columns and rows, column width is equal to wider widget in column, in your case it's label. To avoid stretching first column, span label across all columns using columnSpan argument of addWidget (and button too).
self.gridbox.addWidget(self.label,0,0,1,3)
...
self.gridbox.addWidget(self.button,2,0,1,3)
I would recomend using QtDesigner to create ui, it saves a lot of time and effort and also wysiwyg.

Related

matplotlib.widgets.TextBox: change color

Is there a way to change TextBox text color at any moment? I tried Google already; my question looks too trivial, but I am still at a loss.
TextBox methods:
: dir(matplotlib.widgets.TextBox)
Out[63]:
[
...
'active',
'begin_typing',
'connect_event',
'disconnect',
'disconnect_events',
'drawon',
'eventson',
'get_active',
'ignore',
'on_submit',
'on_text_change',
'position_cursor',
'set_active',
'set_val',
'stop_typing']
AxesWidget superclass methods:
: dir(matplotlib.widgets.AxesWidget)
Out[64]:
[
...
'active',
'connect_event',
'disconnect_events',
'drawon',
'eventson',
'get_active',
'ignore',
'set_active']
Nothing suggestive. At least, to my eye.
A partial answer only - without knowing the fuller application it isn't obvious whether this helps you. There are 2 pieces of text that you can change the color of: the label and the edit box. Below shows how to change each, once.
import matplotlib.widgets
import matplotlib.pyplot as plt
plt.figure(1)
ax = plt.subplot(111)
tb = matplotlib.widgets.TextBox(ax, "Name:", initial="Jane Doe")
tb.label.set_color('red') # label color
tb.text_disp.set_color('blue') # text inside the edit box
If you just want the label text to be different, that persists. But whenever the text inside the edit box (text_disp) is changed, it will be in black again.
This is because widget recreates the text
(by removing and then re-generating and it will be in black again.
The source for the text create method does not have any arguments that the user could modify (color, font size/weight etc) or include as a TextBox instance attribute.
You could write your own subclass that overrides this method. Or perhaps simply setting it after text has been entered is enough for you?

reportlab borderRadius is not working

I'm using reportlab 3.2 with python 2.7.
I'm trying to make put some text in a rounded panel like so:
but I'm getting:
I've tried using borderRadius but it is not making the corners round:
ps_title2 = ParagraphStyle(styles['Normal'],\
fontName=helper.REG_FONT, fontSize=18, textColor=DARK_BLUE,\
leading=22, backColor=LIGHT_BLUE, borderRadius=15)
pr2 = Paragraph('Interpretation summary<br/>something<br/>another thing', ps_title2)
pr2 = Paragraph('my paragraph<br/>something<br/>another thing', ps_title2)
elements.append(pr2)
I know another approach is using a table and know how to make a table an put the info in a table but do not know how to make the table corners round.
Drawing canvas is not a good idea because I don't know the coordinates of the section because depending on the content length it would change.
Any ideas how to make the corners round?
For borderRadius to work, you need to set the following values as well:
borderWidth
borderPadding
borderColor
borderRadius
I looked through the code and figured out that when border color is not set, border radius will not work; also you need to set borderWidth and borderPadding.
Here is what works:
ps_title2 = ParagraphStyle(styles['Normal'],\
fontName=helper.REG_FONT, fontSize=18, textColor=DARK_BLUE,\
leading=22, backColor=LIGHT_BLUE, borderRadius=15, borderColor=LIGHT_BLUE, borderWidth=1, borderPadding=5)

How to set the initial width can use QListWidget and use splitter to adjust the size?

hi,I want to set the initial width can use QListWidget,and use splitter to adjust the size.
I want such as this.
but now,when I use the splitter, is like this.
There's no way to set initial sizes of QSplitter children using Qt Designer. Once you've converted from .ui to .py, you can set the size of each pane using setSizes(list_of_sizes). i.e. for a two-pane window:
splitter = QtWidgets.QSplitter()
splitter.setSizes((50,100))
When using the QSplitter class, you have the setSizes method, which is basically a list of width corresponding to each children
QList<int> widgetsWidth;
widgetsWidth << 100 << 100 << 100 << 400;
ui->mySplitter->setSizes(widgetsWidth);

wxPython ListCtrl : write Colored text

Trying to write string to a ListCtrl , I don't understand the logic completely. Is this the proper way?
self.rightPanel = wx.ListCtrl(spliter, -1, style=wx.LC_REPORT)
self.rightPanel.InsertColumn(0, 'LineNumber')
self.rightPanel.InsertColumn(1, 'log')
self.rightPanel.SetColumnWidth(0, 8)
self.rightPanel.SetColumnWidth(1, 80)
def writeConsole(self,str):
item = wx.ListItem()
item.SetText(str)
item.SetTextColour(wx.RED)
item.SetBackgroundColour(wx.BLACK)
index = self.rightPanel.GetItemCount()
self.rightPanel.InsertItem(item)
self.rightPanel.SetStringItem(index, 0, str(index))
self.rightPanel.SetStringItem(index, 1, item.GetText())
1-Why text is not displayed in color ?
2-Why there are 2 different methods for display text in ListCtrl?
ListCtrl.InsertItem()
ListCtrl.SetStringItem()
I think InsertItem just loads the item to list.SetString but displays the item content.(Not Sure)
SetTextColour() and SetBackgroundColour() are methods of the entire listctrl, not of items.
For items you should use (valid only for report mode):
GetItemTextColour(idx_item)
SetItemTextColour(idx_item, col)
InsertItem(index, item) (item here is an instance of wx.ListItem) is one of the InsertItem() methods to add a new row on a ListCtrl.
SetStringItem(index, col, label, imageId=-1) (where index and col parameters are the row and column indexes for a cell) allows setting strings in any selected column. Other insert methods work only for the first column.
Reference: wxPython in Action, Noel Rappin and Robin Dunn.

Dynamic Spacer in ReportLab

I'm automatically generating a PDF-file with Platypus that has dynamic content.
This means that it might happen that the length of the text content (which is directly at the bottom of the pdf-file) may vary.
However, it might happen that a page break is done in cases where the content is too long.
This is because i use a "static" spacer:
s = Spacer(width=0, height=23.5*cm)
as i always want to have only one page, I somehow need to dynamically set the height of the Spacer, so that the "rest" of the space that is left on the page is taken by the Spacer as its height.
Now, how do i get the "rest" of height that is left on my page?
I sniffed around in the reportlab library a bit and found the following:
Basically, I decided to use a frame into which the flowables will be printed. f._aH returns the height of the Frame (we could also calculate this by hand). Subtracting the heights of the other two flowables, which we get through wrap, we get the remaining height which is the height of the Spacer.
elements.append(Flowable1)
elements.append(Flowable2)
c = Canvas(path)
f = Frame(fx, fy,fw,fh,showBoundary=0)
# compute the available height for the spacer
sheight = f._aH - (Flowable1.wrap(f._aW,f._aH)[1] + Flowable2.wrap(f._aW,f._aH)[1])
# create spacer
s = Spacer(width=0, height=sheight)
# insert the spacer between the two flowables
elements.insert(1,s)
# create a frame from the list of elements
f.addFromList(elements,c)
c.save()
tested and works fine.
As far as i can see you want to have footer, right?
Then you should do it like:
def _laterPages(canvas, doc):
canvas.drawImage(os.path.join(settings.PROJECT_ROOT, 'templates/documents/pics/footer.png'), left_margin, bottom_margin - 0.5*cm, frame_width, 0.5*cm)
doc = BaseDocTemplate(filename,showBoundary=False)
doc.multiBuild(flowble elements, _firstPage, _laterPages)

Categories