[Solved] Opaque label in a transparent widget
-
wrote on 16 Jun 2012, 15:46 last edited by
Hi,
I am new to Qt. I am creating a widget which is transpernt, i want some opaque labels on the widget.
How can i create opaque label
This is my code
@QApplication a(argc, argv);
QWidget *w = new QWidget();
w->setWindowOpacity(0.7);
w->setWindowFlags(Qt::FramelessWindowHint);w->setPalette(QPalette(Qt::black)); w->setFixedHeight(240); w->setFixedWidth(500); QLabel *lblImg = new QLabel(); lblImg->setText("<img >"); w->show(); return a.exec();
@
Thank you
Vishnu V[edit: fixed typo in title, Eddy]
-
wrote on 16 Jun 2012, 17:02 last edited by
Hi, Vishnu. A widget's opacity is inherited by it's children, thus a child cannot be more opaque than it's parent. I think your solution here would be to set the background color of the widget to a translucent color.
I'm a QML guy myself, though, so I'm not sure how to do that on a QWidget. I've got this far, though, and it's a start:
@
QWidget *w = new QWidget();
w->setWindowFlags(Qt::FramelessWindowHint);
w->setAttribute(Qt::WA_TranslucentBackground);w->setPalette(QPalette(Qt::black)); w->setStyleSheet("background:rgba(0,0,0,70%)"); w->setFixedHeight(240); w->setFixedWidth(500); QLabel *lblImg = new QLabel(w); lblImg->setText("Meh!"); w->show();
@
-
wrote on 16 Jun 2012, 17:34 last edited by
Thank you very much, Problem solved :-)
-
wrote on 16 Jun 2012, 17:48 last edited by
I'm glad to hear it. I recommend going ahead and posting your final changes that solved the problem so that future readers who have the same problem can see the solution too. Plus, I'd like to see what you did to fix mine, which (at least for me) was not displaying correctly.
-
wrote on 17 Jun 2012, 08:57 last edited by
This is my code @#include <QtGui/QApplication>
#include "weather.h"
#include<QLabel>
#include<QLayout>
#include<stdio.h>
#include<string.h>
#include <string>
#include <iostream>char tag[200],complete[200];
char value[100];
FILE *f;
char c;
void read_tag(int i){
int j=0;
strcpy(tag,"");
int k=0;
while((c=fgetc(f))!=EOF){
complete[k++]=c;
if(c=='<'){
while((c=fgetc(f))!=EOF){if(c=='>'){ complete[k++]=c; complete[k]='\0'; tag[j]=='\0'; return; } tag[j]=c; complete[k]=c; k++; j++; } break; } } complete[k]='\0'; tag[j]=='\0'; return;
}
int find_no_tags(char *tag){
int i,no=0;
for(i=0;i<strlen(tag);i++){
if(tag[i]=='/'){
no++;
}
}
return no+1;}
void find_tag(char *tag)
{
int no=find_no_tags(tag);
printf("no of tags=%d\n",no);}
int get_data(char data[],char arg[]){
int flag=0;
int i,j;
char c;
char tmp[150];
for(i=0;i<strlen(data);i++){
if(data[i]=='='){
tmp[i]='\0';
break;
}
tmp[i]=data[i];
}
if(!strcmp(tmp,arg)){
i=i+2;
j=0;
for(;i<strlen(data);i++){
if(data[i]=='"'){
tmp[j]='\0';
break;
}
tmp[j]=data[i];
j++;} flag=1; strcpy(value,tmp); //printf("%s\n\n\n\n",value); } return flag;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget *w = new QWidget();
w->setWindowFlags(Qt::FramelessWindowHint);
w->setAttribute(Qt::WA_TranslucentBackground);
w->setStyleSheet("background:rgba(0,0,0,70%)");
w->setFixedHeight(240);
w->setFixedWidth(500);system("wget -O weather http://www.google.com/ig/api?weather=kottayam"); QLabel *head = new QLabel(w); head->setGeometry(0,0,500,20); QLabel *foot = new QLabel(w); foot->setGeometry(0,210,500,30); QLabel *lblCity = new QLabel(w); lblCity->setGeometry(220,20,280,30); lblCity->setStyleSheet("QLabel { color : white; }"); QLabel *lblTemp = new QLabel(w); lblTemp->setGeometry(220,50,280,30); lblTemp->setStyleSheet("QLabel { color : white; }"); QLabel *lblCondition = new QLabel(w); lblCondition->setGeometry(220,80,280,30); lblCondition->setStyleSheet("QLabel { color : white; }"); QLabel *lblWind = new QLabel(w); lblWind->setGeometry(220,110,280,30); lblWind->setStyleSheet("QLabel { color : white; }"); QLabel *lblHumidity = new QLabel(w); lblHumidity->setGeometry(220,140,280,30); lblHumidity->setStyleSheet("QLabel { color : white; }"); QLabel *lblDate = new QLabel(w); lblDate->setGeometry(220,170,280,30); lblDate->setStyleSheet("QLabel { color : white; }"); QLabel *com = new QLabel(w); com->setGeometry(220,200,280,10); QLabel *lblImg = new QLabel(w); lblImg->setGeometry(0,20,220,190); int i=0; f = fopen("weather","r"); QString temp; while(c!=EOF){ read_tag(i); if(get_data(tag,"city data")){ lblCity->setText(value); } else if(get_data(tag,"condition data")){ temp = "Condition:"; temp=temp+value; lblCondition->setText(temp); } else if(get_data(tag,"humidity data")){ lblHumidity->setText(value); } else if(get_data(tag,"icon data")){ printf("icon=%s\n",value); char icon[100]=""; strcat(icon,"<img >"); printf("%s",icon); lblImg->setText(icon); } else if(get_data(tag,"wind_condition data")){ lblWind->setText(value); } else if(get_data(tag,"forecast_date data")){ lblDate->setText(value); } else if(get_data(tag,"temp_c data")){ temp = "Temp:"; temp=temp+value+" C"; lblTemp->setText(temp); } if(strcmp(complete,"</current_conditions>")==0){ break; } } fclose(f); w->show(); return a.exec();
}
@ -
wrote on 16 Jan 2015, 05:36 last edited by
Hi
i have a problem like
using qt widget label i want to display temperature value if every time user click the button, the temperature value should get changeusing qt 5.4
visual studio 2010thanks
rishi.qaa@gmail.com -
wrote on 16 Jan 2015, 05:36 last edited by
Hi
i have a problem like
using qt widget label i want to display temperature value if every time user click the button, the temperature value should get changeusing qt 5.4
visual studio 2010thanks
rishi.qaa@gmail.com