Well, this is my try to load a style stored in Postgres database.
QGIS saves the layers in a table called layer_styles
The column I need is styleqml, so I need to make a query like that:
select styleqml from public.layer_styles;
There are another descriptive columns like stylename or description I can use for help to choose the properly style. I could do:
select stylename, description, styleqml from public.layer_styles;
I have used only styleqml column and I have stored all the records in a list
Finnally I only have to set the style in my layer like that:
self.vlayer.applyNamedStyle(mylist[n])
I show a snippet of my code. Sorry if there are mistakes or if I am saying any silliness, but it works for me:
self.loadStyles = QtSql.QSqlQuery(self.conexion)
self.listOfStyles=[]
if self.loadStyles:
self.loadStyles.exec_("SELECT styleqml FROM public.layer_styles")
while self.loadStyles.next():
self.listOfStyles.append(unicode(self.loadStyles.value(0)))
self.myStyle = self.listOfStyles[1] # 1 in my case
self.vlayer.applyNamedStyle(self.myStyle)