How to show more number(folder) of images in Qlabel or QScrollArea?
QImage image("E:/Raul/Images");
ui.label->setPixmap(QPixmap::fromImage(image));
Like this but i want more number images will load in one label.
Result:
Code:
#include <QApplication>
#include <QLabel>
#include <QLineEdit>
#include <QPointer>
#include <QPushButton>
#include <QVBoxLayout>
#include <QWizardPage>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget widget;
QVBoxLayout *layout=new QVBoxLayout();
QLabel *label=new QLabel("<img src=:/0_0.jpg align=middle><img src=:/0_1.jpg align=middle><strong>Hello</strong> "
"<font color=red>Sai Raul!");
layout->addWidget(label);
widget.setLayout(layout);
widget.show();
return a.exec();
//
}
QLabel is not a web browser, therefore hyperlinks like <img src=/media/cc0-images/grapefruit-slice-332-332.jpg/> doesn't work, but why images from resources can not do it))).
Related
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget w;
QPushButton *trankil = new QPushButton("Clique&&Release", &w);
QVBoxLayout *layoutrkl = new QVBoxLayout;
layoutrkl->addWidget(trankil);
//trankil->move(10,10);
int resultat = 2;
QLCDNumber *lcd = new QLCDNumber(&w);
QLabel *lelabel = new QLabel("bonsoir");
QPushButton *trankil2 = new QPushButton("Clique&&Release2", &w);
layoutrkl->addWidget(trankil2);
layoutrkl->addWidget(lelabel);
layoutrkl->addWidget(lcd);
QObject::connect(trankil, SIGNAL(clicked()),lcd, SLOT(display(resultat)));
w.setLayout(layoutrkl);
w.show();
return a.exec();
}
The connect doesn't work and i don't understand why at all !
There is no problem about how it appear, but if i click the QPushbutton, the QLCD won't display resultat
Thanks for your help
PS : There is my includes :
#include <QApplication>
#include <QVBoxLayout>
#include <QLCDNumber>
#include <QPushButton>
#include <QLabel>
#include <QObject>
If you debug it.
QObject::connect: No such slot QLCDNumber::display(resultat)
display(resultat) is not a slot function.
You can try the following:
QObject::connect(trankil, &QPushButton::clicked, lcd, [&](){
lcd->display(QString::number(resultat));
});
How should I center my QLabel derived widget papyrus inside a QScrollArea?
QScrollArea *scroll_area = new QScrollArea(this);
scroll_area->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
scroll_area->setWidgetResizable(true);
scroll_area->setBackgroundRole(QPalette::Dark);
papyrus = new Papyrus(scroll_area);
scroll_area->setWidget(papyrus);
setCentralWidget(scroll_area);
resize(800, 600);
This is the snippet I am using but my widget sticks to the top left...
(main.cpp example):
#include <QApplication>
#include "MainWindow.h"
#include <QScrollArea>
#include <QLabel>
#include <QHBoxLayout>
int main(int argc, char** argv)
{
QApplication a(argc, argv);
QLabel label("Label");
label.setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
QScrollArea area;
area.setWidgetResizable(true);
area.setWidget(&label);
area.show();
return a.exec();
}
I have read a documentation and aswell many sites on website.
Unfortunatly I didn't find answer to my question.
Is there any chance(I believe there is) to fill background outside the popup window? Let me explain: If i have window like of my whole app with resolution 500x500 [px] and I create a popup window 300x300 in the middle - it means I have 200 px in each side "parent-window". Is there any chance (method, flag) to fill background in gray color?
Image: https://imgur.com/Hunev58
Modifying the palette does the job. Here you get a purple background when the MessageBox is shown , and come back to normal once clicked
#include <QApplication>
#include <QMainWindow>
#include <QVBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QMessageBox>
#include <QPalette>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow w;
QVBoxLayout mainLayout;
QLabel foolabel("FooLabel");
QPushButton foobutton("FooButton");
mainLayout.addWidget(&foolabel);
mainLayout.addWidget(&foobutton);
QWidget window;
window.setLayout(&mainLayout);
w.setCentralWidget(&window);
QPalette palette = QApplication::palette(&w);
palette.setColor(QPalette::Inactive,QPalette::Window,QColor(138,43,226));
w.setPalette(palette);
w.show();
QMessageBox box(&w);
box.exec();
return a.exec();
}
I'd like to show and then close a dialog after 5 seconds. The dialog needs to be automatically resized (horizontally and vertically) based on the content of a label. Here is my code:
#include <QApplication>
#include <QDialog>
#include <QLabel>
#include <QTimer>
void notify (int intTime=1000)
{
QDialog notify;
notify.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
notify.setWindowFlag(Qt::FramelessWindowHint);
QLabel *lbl = new QLabel(¬ify);
lbl->setText("This is a test This is a test This is a test This is a test This is a test This is a test This is a test");
QApplication::processEvents();
notify.adjustSize();
QTimer::singleShot(intTime, ¬ify, SLOT(close()));
notify.exec();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
notify(5000);
exit(0);
// return a.exec();
}
It does not not expand the dialog based on the label size. Here is how it looks:
How can I fix it? (Please also let me know if there is better way of doing this.)
I am using Qt5 in Linux.
Since you have not used a QLayout the QLabel will be displayed as large as you can, a possible request is to change the size of QDialog to the recommended size of QLabel with sizeHint():
#include <QApplication>
#include <QDialog>
#include <QLabel>
#include <QTimer>
void notify (int intTime=1000)
{
QDialog notify;
notify.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
notify.setWindowFlag(Qt::FramelessWindowHint);
QLabel *lbl = new QLabel(¬ify);
lbl->setText("This is a test This is a test This is a test This is a test This is a test This is a test This is a test");
QApplication::processEvents();
notify.resize(lbl->sizeHint());
QTimer::singleShot(intTime, ¬ify, SLOT(close()));
notify.exec();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
notify(5000);
exit(0);
// return a.exec();
}
The other possible solution is to use a QLayout:
#include <QApplication>
#include <QDialog>
#include <QLabel>
#include <QTimer>
#include <QVBoxLayout>
void notify (int intTime=1000)
{
QDialog notify;
QVBoxLayout *lay = new QVBoxLayout(¬ify);
//notify.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
notify.setWindowFlag(Qt::FramelessWindowHint);
QLabel *lbl = new QLabel;
lay->addWidget(lbl);
lbl->setText("This is a test This is a test This is a test This is a test This is a test This is a test This is a test");
QApplication::processEvents();
QTimer::singleShot(intTime, ¬ify, SLOT(close()));
notify.exec();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
notify(5000);
exit(0);
// return a.exec();
}
This code
#include <QtWidgets/QApplication>
#include <QLabel>
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
QLabel *label = new QLabel("my first app");
label->show();
return app.exec();
}
Causing an error:
QLabel: there is no such directory
I am using Qt 5.0.1 in Windows
change
#include <QLabel>
to #include <QtWidgets/QLabel>
This is where QLabel actually resides (if this is that QLabel that you want)
Put QT += widgets in your .pro file.