How to draw a line between the widgets in Qscrollarea using pyqt4 - python-2.7

Here is my code i created multiple widget in qscrollarea. In between the each widget i want to draw a line.Can any one please tell me how can i draw line in between the each widget of the scroll area.
self.mainw = QtGui.QWidget()
self.scrollArea_left.setWidget(self.mainw)
self.ordersvbox = QtGui.QGridLayout(self.mainw)
self.w1 = QtGui.QWidget()
self.v1 = QtGui.QVBoxLayout(spacing=0)
self.v1.setContentsMargins(0, 0, 0, 0)
self.w1.setLayout(self.v1)
self.h1 = QtGui.QHBoxLayout()
self.l1 = QtGui.QLabel("#A")
self.lprogress = QtGui.QLabel("Porgress")
self.lamount = QtGui.QLabel("200 Rs")
self.items_count = QtGui.QLabel("2 items")
self.h1.addWidget(self.l1)
self.h1.addWidget(self.lprogress)
self.h1.addWidget(self.lamount)
self.v1.addLayout(self.h1)
self.v1.addWidget(self.items_count)
self.ordersvbox.addWidget(self.w1,0,0)
self.w2 = QtGui.QWidget()
self.v2 = QtGui.QVBoxLayout(self.w2)
self.h2 = QtGui.QHBoxLayout()
self.l2 = QtGui.QLabel("#B")
self.lprogress2 = QtGui.QLabel("x")
self.lamount2 = QtGui.QLabel("300 RS")
self.items_count2 = QtGui.QLabel(" 2 items")
self.h2.addWidget(self.l2)
self.h2.addWidget(self.lprogress2)
self.h2.addWidget(self.lamount2)
self.v2.addLayout(self.h2)
self.v2.addWidget(self.items_count2)
self.ordersvbox.addWidget(self.w2,1,0)
self.w3 = QtGui.QWidget()
self.v3 = QtGui.QVBoxLayout(self.w3)
self.h3 = QtGui.QHBoxLayout()
self.l3 = QtGui.QLabel("#C")
self.lprogress3 = QtGui.QLabel("z")
self.lamount3 = QtGui.QLabel("200 RS")
self.items_count3 = QtGui.QLabel(" 2 items")
self.h3.addWidget(self.l3)
self.h3.addWidget(self.lprogress3)
self.h3.addWidget(self.lamount3)
self.v3.addLayout(self.h3)
self.v3.addWidget(self.items_count3)
self.ordersvbox.addWidget(self.w3,2,0)

Related

render Image not outputting Shiny

output$plot <- renderImage({
outfile <- tempfile(fileext = '.png')
png(outfile, width = 400, height = 300)
venn.diagram(
x = list(
T = T,
I = I
),
main = "Venn Diagram ",
filename =outfile, output=TRUE,
lwd = 2,na = "remove",
fill = c("orange", "blue"),
alpha = c(0.5,0.5),
label.col = "black",
cex=1.5,
fontface = "plain",
cat.col = c("cornflowerblue", "pink"),
cat.cex = 1.5,
cat.fontfamily = "serif",
cat.fontface = "plain",
cat.dist = c(0.05, 0.05),
cat.pos = c(-20, 14),
cat.default.pos = "text",
scaled = FALSE
)
dev.off()
list(src = outfile,
contentType = 'image/png',
width = 400,
height = 300,
alt = "This is alternate text")
}, deleteFile = TRUE)
I was trying plot a venn diagram using this code. But it only displays This is alternate text and not outputting any image on the app, Any Idea ?
Try to create a reactive graph as shown below
output$plot <- renderImage({
vennd <- reactive({venn.diagram(
x = list(
T = T,
I = I
),
main = "Venn Diagram ",
filename =outfile, output=TRUE,
lwd = 2,na = "remove",
fill = c("orange", "blue"),
alpha = c(0.5,0.5),
label.col = "black",
cex=1.5,
fontface = "plain",
cat.col = c("cornflowerblue", "pink"),
cat.cex = 1.5,
cat.fontfamily = "serif",
cat.fontface = "plain",
cat.dist = c(0.05, 0.05),
cat.pos = c(-20, 14),
cat.default.pos = "text",
scaled = FALSE
)
})
outfile <- tempfile(fileext = '.png')
png(outfile, width = 400, height = 300)
vennd()
dev.off()
list(src = outfile,
contentType = 'image/png',
width = 400,
height = 300,
alt = "This is alternate text")
}, deleteFile = TRUE)
output$plot <- renderImage({
vennd <- reactive({venn.diagram(
x = list(
T = T,
I = I
),
main = "",
filename =outfile, output=TRUE,
lwd = 2,na = "remove",imagetype="png",
fill = c("orange", "blue"),
alpha = c(0.5,0.5),
label.col = "black",
cex=1.5,
fontface = "plain",
cat.col = c("cornflowerblue", "pink"),
cat.cex = 1.5,
cat.fontfamily = "serif",
cat.fontface = "plain",
cat.dist = c(0.05, 0.05),
cat.pos = c(-20, 14),
cat.default.pos = "text",
scaled = FALSE
)
})
outfile <- tempfile(fileext = '.png')
png(outfile, width = 500, height = 500,type="cairo")
vennd()
dev.off()
list(src = outfile,
contentType = 'image/png',
width = 500,
height = 500,
alt = "This is alternate text")
}, deleteFile = TRUE)
Need to add imagetype="png" and type="cairo" thank you #YBS

Problem customize the height of column bar

The column bar is too small. And I couldn't adjust their height. The screen shot is attached here: https://prnt.sc/p09hj9.
I have tried all the methods of column series at https://www.amcharts.com/docs/v4/reference/columnseries/.
am4core.ready(function() {
// Create chart instance
var chart = am4core.create("historical_monthly_chart_range", am4charts.XYChart);
// Push data into the charts
var dateAxis = chart.xAxes.push(new am4charts.DateAxis());
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
var series = chart.series.push(new am4charts.LineSeries());
series.name = "Price Range";
valueAxis.title.text = 'Price (S$ psf)';
series.dataFields.dateX = "date";
series.dataFields.openValueY = "min";
series.dataFields.valueY = "max";
series.tooltipText = "{date} \n Maximum: {max} \n Average: {average} \n Minimum: {min} \n Volume: {value}";
// Setting the appearance
series.tooltip.background.cornerRadius = 20;
series.tooltip.background.strokeOpacity = 0;
series.tooltip.pointerOrientation = "vertical";
series.tooltip.label.minWidth = 40;
series.tooltip.label.minHeight = 40;
series.tooltip.label.textAlign = "left";
series.tooltip.label.textValign = "middle";
series.fillOpacity = 0.5;
series.tensionX = 0.8;
series.fill = am4core.color("#697e69");
var series2 = chart.series.push(new am4charts.LineSeries());
series2.name = "Minimum Price";
series2.dataFields.dateX = "date";
series2.dataFields.valueY = "min";
series2.stroke = am4core.color("#697e69");
series2.tensionX = 0.8;
var series_average = chart.series.push(new am4charts.LineSeries());
series_average.name = "Average Price";
series_average.dataFields.valueY = "average";
series_average.dataFields.dateX = "date";
series_average.stroke = am4core.color("#000");
/* Bar chart series */
var barSeries = chart.series.push(new am4charts.ColumnSeries());
barSeries.dataFields.valueY = "value";
barSeries.dataFields.dateX = "date";
barSeries.fill = am4core.color("#000");
barSeries.columns.width = am4core.percent(60);
chart.cursor = new am4charts.XYCursor();
chart.cursor.xAxis = dateAxis;
chart.legend = new am4charts.Legend();
});
There is a bounty on this issue from AM charts however one workaround can be using scrollbar in Y axis like this following:
chart.scrollbarY = new am4core.Scrollbar();
This is not the best solution i agree but you can use it to slightly zoom with the buttons and scale and see
let me know if it works!

how to get the all products in dictionary in each iteration of the for loop

Here is my sample code i want to show all my products in widget so i took as dictionary in for loop, but i am not getting the all products in the dictionary last product is overwrite the previous one.Can any one please help me where i did a mistake.Thank you in advance.
Given below is my code:
products_list = {"Givers":{"price": 140,"Quantity":100,"Discount":0,"Total_price":14000,"Paid_amount":14000},"New_Member":{"price": 1200,"Quantity":10,"Discount":0,"Total_price":12000,"Paid_amount":12000},"YearMembers_Ribbons":{"price": 110,"Quantity":0,"Discount":0,"Total_price":1100,"Paid_amount":1100}}
for key,value in products_list.items():
self.widget_orders_info = QtGui.QWidget()
self.widget_orders_info.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.widget_orders_info.setStyleSheet("QWidget {background-color: blue;color: white;}")
self.order_info_vbox = QtGui.QVBoxLayout(self.widget_orders_info)
self.title_hbox = QtGui.QHBoxLayout()
self.orderdetail_label = QtGui.QLabel("Order_Details(22HRS)",alignment =QtCore.Qt.AlignCenter,objectName="small")
self.close_pushbtn = QtGui.QPushButton("Close")
self.title_hbox.addWidget(self.orderdetail_label)
self.title_hbox.addStretch()
self.title_hbox.addWidget(self.close_pushbtn)
self.close_pushbtn.clicked.connect(self.widget_orders_info.close)
self.order_info_vbox.addLayout(self.title_hbox)
self.line = QtGui.QFrame(frameShape=QtGui.QFrame.HLine)
self.order_info_vbox.addWidget(self.line)
self.order_hbox = QtGui.QHBoxLayout()
keys = value.keys()
values = value.values()
self.line1 = QtGui.QFrame(frameShape=QtGui.QFrame.VLine)
self.order_hbox.addWidget(self.line1)
self.items_Vboxlay = QtGui.QVBoxLayout()
self.vbox2 = QtGui.QVBoxLayout()
self.item_label = QtGui.QLabel(str(key), objectName="small")
self.vbox2.addWidget(self.item_label)
self.hbox1 = QtGui.QHBoxLayout()
self.price = QtGui.QLabel(keys[1]+": " +str(values[1]))
self.qnty =QtGui.QLabel(keys[4]+": "+str(values[4]))
self.discount = QtGui.QLabel(keys[0]+ ": " +u'\u20B9 '+ str(values[0]))
self.totalprice =QtGui.QLabel(keys[2]+ ": "+u'\u20B9 '+ str(values[2]))
self.paid = QtGui.QLabel(keys[3] + ": "+u'\u20B9 '+ str(values[3]))
self.hbox1.addWidget(self.price)
self.hbox1.addWidget(self.qnty)
self.hbox1.addWidget(self.discount)
self.hbox1.addWidget(self.totalprice)
self.hbox1.addWidget(self.paid)
self.line4 = QtGui.QFrame();self.line4.setFrameShape(QtGui.QFrame.HLine)
self.vbox2.addLayout(self.hbox1)
self.vbox2.addLayout(self.h2box)
self.vbox2.addWidget(self.line1)
self.items_Vboxlay.addLayout(self.vbox2)
self.order_hbox.addLayout(self.items_Vboxlay)
self.order_info_vbox.addLayout(self.order_hbox)
self.add_hbox = QtGui.QHBoxLayout()
self.print_btn = QtGui.QPushButton("Print")
self.print_btn.clicked.connect(partial(self.print_function,type))
self.add_hbox.setAlignment(QtCore.Qt.AlignCenter)
self.add_hbox.addWidget(self.print_btn)
self.order_info_vbox.addLayout(self.add_hbox)
self.widget_orders_info.show()
self.widget_orders_info.resize(500,300)
Sorry, I have Python-3 andPyQt5. I think my example should help you.
import sys
from functools import partial
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class Window(QMainWindow):
def __init__(self):
super().__init__()
products_list = {
"Givers":{
"price": 140,
"Quantity": 100,
"Discount": 0,
"Total_price":14000,
"Paid_amount":14000},
"New_Member":{
"price": 1200,
"Quantity": 10,
"Discount": 0,
"Total_price":12000,
"Paid_amount":12000},
"YearMembers_Ribbons":{
"price": 110,
"Quantity": 0,
"Discount": 0,
"Total_price":1100,
"Paid_amount":1100}
}
# *1 +++
self.widget_orders_info = QWidget()
self.widget_orders_info.setWindowFlags(Qt.FramelessWindowHint)
self.widget_orders_info.setStyleSheet("QWidget {background-color: blue;color: white;}")
self.order_info_vbox = QVBoxLayout(self.widget_orders_info)
self.title_hbox = QHBoxLayout()
self.orderdetail_label = QLabel("Order_Details(22HRS)",
alignment=Qt.AlignCenter,
objectName="small")
self.close_pushbtn = QPushButton("Close")
self.title_hbox.addWidget(self.orderdetail_label)
self.title_hbox.addStretch()
self.title_hbox.addWidget(self.close_pushbtn)
self.close_pushbtn.clicked.connect(self.widget_orders_info.close)
self.order_info_vbox.addLayout(self.title_hbox)
self.line = QFrame(frameShape=QFrame.HLine)
self.order_info_vbox.addWidget(self.line)
self.order_hbox = QHBoxLayout()
# *2 +++
self.line1 = QFrame(frameShape = QFrame.VLine)
self.order_hbox.addWidget(self.line1)
self.items_Vboxlay = QVBoxLayout()
self.vbox2 = QVBoxLayout()
for key, value in products_list.items():
# self.widget_orders_info = QWidget()
# ...
# transferred from the `for` loop, see `* 1 +++`
# ...
# self.order_hbox = QHBoxLayout()
# keys = value.keys()
# values = value.values()
keys = [ vk for vk in value.keys()]
values = [ vv for vv in value.values()]
# self.line1 = QFrame(frameShape = QFrame.VLine)
# ...
# transferred from the `for` loop, see `* 2 +++`
# ...
# self.vbox2 = QVBoxLayout()
self.item_label = QLabel(str(key), objectName="small")
self.vbox2.addWidget(self.item_label)
self.hbox1 = QHBoxLayout()
self.price = QLabel(keys[1] + ": " + str(values[1]))
self.qnty = QLabel(keys[4] + ": " + str(values[4]))
self.discount = QLabel(keys[0] + ": " + u'\u20B9 ' + str(values[0]))
self.totalprice = QLabel(keys[2] + ": " + u'\u20B9 ' + str(values[2]))
self.paid = QLabel(keys[3] + ": " + u'\u20B9 ' + str(values[3]))
self.hbox1.addWidget(self.price)
self.hbox1.addWidget(self.qnty)
self.hbox1.addWidget(self.discount)
self.hbox1.addWidget(self.totalprice)
self.hbox1.addWidget(self.paid)
self.line4 = QFrame()
self.line4.setFrameShape(QFrame.HLine)
self.vbox2.addLayout(self.hbox1)
# self.vbox2.addLayout(self.h2box) # ??????????????????????????
self.vbox2.addWidget(self.line1)
self.items_Vboxlay.addLayout(self.vbox2)
self.order_hbox.addLayout(self.items_Vboxlay)
self.order_info_vbox.addLayout(self.order_hbox)
self.add_hbox = QHBoxLayout()
self.print_btn = QPushButton("Print")
self.print_btn.clicked.connect(partial(self.print_function, type))
self.add_hbox.setAlignment(Qt.AlignCenter)
self.add_hbox.addWidget(self.print_btn)
self.order_info_vbox.addLayout(self.add_hbox)
self.widget_orders_info.show()
self.widget_orders_info.resize(500,300)
def print_function(self, t):
print("--- t ->", t)
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
w = Window()
# w.show()
sys.exit(app.exec_())

replacing a new interface with old one in tkinter

I've created a class that has a function called mainScreen(). It simply prints the main screen with two buttons on it. If you press any button, it must go to another function called signup(). I want to clear the whole frame and create new widgets but I can't clear the widgets
class graphics:
def __init__(self, master):
self.root = master
def mainscreen(self):
helv36 = tkFont.Font(family='Century Gothic', size=20)
mainFrame = Frame(self.root)
mainFrame.config(relief='sunken', width=1280, height=720, bg='light
blue')
mainFrame.pack(expand='yes', fill='both')
inButton = Button(mainFrame, text = "Sign up", bd = 10, relief =
GROOVE, font = helv36)
inButton.bind("<Button-1>", self.signup)
inButton.place(bordermode = OUTSIDE, width =160, height = 60, x =
600, y = 300)
upButton = Button(mainFrame, text = "Sign in", bd = 10, relief =
GROOVE, font = helv36)
upButton.bind("<Button-1>", self.signup)
upButton.place(bordermode = OUTSIDE, width =160, height = 60, x =
600, y = 400)
mainFrame.pack_propagate(FALSE)
self.root.mainloop()
def signup(self,event):
signUpShow = Frame(self.root)
signUpShow.config(relief='sunken', width=1280, height=720, bg='light
yellow')
signUpShow.pack(expand='yes', fill='both')
You __init__ needs to have its code indented and it needs a call to mainscreen. The solution to mainFrame being local within mainscreen is to make it also an attribute.
self.mainframe = mainFrame = Frame(self.root)
Then you can access self.mainframe within signup.

How to show and hide QtGui.QGridLayout in PySide

Here I am creating a layout called _grid and putting few labels and slider in the layout .
Now I want this layout to be hide first then onclick I want to show it .
If there is any simple function associated with QtGui.QGridLayout to show and hide.
I googled and found this is available for QWidget by QWidget.hide()
class TimeSlider (QtGui.QVBoxLayout):
def __init__ (self):
QtGui.QVBoxLayout.__init__ (self)
# Put everything in a grid
_grid = QtGui.QGridLayout ()
self.addLayout (_grid)
# Slider limit labels
_grid.addWidget (QtGui.QLabel (''), 0, 0)
_labelLayout = QtGui.QHBoxLayout ()
_grid.addLayout (_labelLayout, 0, 1)
self.lower = QtGui.QLabel ('LOW')
_labelLayout.addWidget (self.lower)
self.higher = QtGui.QLabel ('HIGH')
self.higher.setAlignment (QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
_labelLayout.addWidget (self.higher)
# Slider
_grid.addWidget (QtGui.QLabel (''), 1, 0)
self.sliderBarLayout = QtGui.QHBoxLayout ()
self.sliderBarLayout.setSpacing (0)
_grid.addLayout (self.sliderBarLayout, 1, 1)
self.sliderBarLayout.addWidget (self.leftEndstop)
self.slider = QtGui.QSlider (QtCore.Qt.Horizontal)
self.slider.setTickPosition (QtGui.QSlider.TicksBelow)
self.slider.setTracking (True)
self.slider.setMinimumWidth (40)
self.slider.setPageStep (1)
self.sliderBarLayout.addWidget (self.slider)
self.rightEndstop = RightEndstop (self, self.root)
self.sliderBarLayout.addWidget (self.rightEndstop)
import sys, time
from PyQt4 import QtGui, QtCore
class TimeSlider (QtGui.QVBoxLayout):
def __init__ (self):
QtGui.QVBoxLayout.__init__ (self)
# Put everything in a grid
_manLayout = QtGui.QVBoxLayout ()
self._frame = QtGui.QFrame();
_manLayout.addWidget(self._frame)
_grid = QtGui.QGridLayout (self._frame)
# Slider limit labels
_grid.addWidget (QtGui.QLabel (''), 0, 0)
_labelLayout = QtGui.QHBoxLayout ()
_grid.addLayout (_labelLayout, 0, 1)
self.lower = QtGui.QLabel ('LOW')
_labelLayout.addWidget (self.lower)
self.higher = QtGui.QLabel ('HIGH')
self.higher.setAlignment (QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
_labelLayout.addWidget (self.higher)
# Slider
_grid.addWidget (QtGui.QLabel (''), 1, 0)
self.sliderBarLayout = QtGui.QHBoxLayout ()
self.sliderBarLayout.setSpacing (0)
_grid.addLayout (self.sliderBarLayout, 1, 1)
# self.sliderBarLayout.addWidget (self.leftEndstop)
self.slider = QtGui.QSlider (QtCore.Qt.Horizontal)
self.slider.setTickPosition (QtGui.QSlider.TicksBelow)
self.slider.setTracking (True)
self.slider.setMinimumWidth (40)
self.slider.setPageStep (1)
self.sliderBarLayout.addWidget (self.slider)
self._frame.setLayout(_grid)
self.addLayout (_manLayout)
#self.rightEndstop = RightEndstop (self, self.root)
# self.sliderBarLayout.addWidget (self.rightEndstop)
def show(self):
self._frame.show()
def hide(self):
self._frame.hide()
def isHidden(self):
return self._frame.isHidden()
class NewTimeSliderTest(QtGui.QWidget):
def __init__(self, parent=None, total=20):
super(NewTimeSliderTest, self).__init__(parent)
self.newTimeSlider = TimeSlider()
self.resize(841, 474)
self.newTimeSlider.hide()
self.button = QtGui.QPushButton('Show/Hide')
self.button.clicked.connect(self.handleButton)
main_layout = QtGui.QGridLayout()
main_layout.addWidget(self.button, 0, 0)
main_layout.addLayout(self.newTimeSlider, 0, 1)
self.setLayout(main_layout)
self.setWindowTitle('Test')
self._active = False
def handleButton(self):
#self.newTimeSlider.show()
isHidden = self.newTimeSlider.isHidden()
if isHidden:
self.newTimeSlider.show()
else:
self.newTimeSlider.hide()
app = QtGui.QApplication(sys.argv)
bar = NewTimeSliderTest(total=101)
bar.show()
sys.exit(app.exec_())
How about this ?
Any time you can all like this.
self.newTimeSlider.show()
or
self.newTimeSlider.hide()