I need to create a customized and animated loading screen in Qt, and I don't need a progress bar.
I want to do something like this:
Anyone knows how can I do that?
Can I use, for example, QSplashScreen?
Try QMovie to load an animation`
QMovie * movie = new QMovie("http://i.stack.imgur.com/vdYAH.gif");
You can either load the movie directly to a label, hide and show it when necessary
QLabel label;
label.setMovie(movie);
movie->start();
Or read the frames of the movie to set splash screen pixmap continuously
connect(movie, SIGNAL(frameChanged(int)), this, SLOT(setSplashScreenPixmap(int)));
movie->start();
Related
I'm working on a WinUI3 desktop application in c++. I was trying to achieve an experience where we can show a ProgressRing in the center of the screen when there is a delay in screen update. In my application, my window has a Canvas as its content and that canvas contains many widgets. I want to put a new Canvas as an overlay on top of the existing Canvas and show a ProgressRing on the new Overlay Canvas and I was able to achieve an experience like this.
The overlay Canvas in the image has a background color as transparent, I wanted to make the overlay canvas translucent. So that all the widgets below the overlay canvas will look like grayed-out non-interactive widgets.
I would be of great help if you could help me with this issue.
Thank you,
Harshithraj P
One way to do that is to set the Background("Black" maybe?) and the Opacity depending on how you want it to look.
I am trying to use a custom icon in a QtMessageBox, but can't resize the icon at all. The box shows up fine, but the icon is too large.
I've tried code from a similar question, but it didn't work.
QPixmap p(80,80);
p.scaled(80,80); //this doesn't seem to change anything
p.load("checkmark.png");
box->setIconPixmap(p);
How do I do this?
It is pointless to scale the pixmap before loading it, scale it afterwards.
QPixmap p("checkmark.png");
auto newPixmap = p.scaled(80, 80);
box->setIconPixmap(newPixmap);
Here's my end goal: I want to transition between two images. I want the original image to fade out, and at the same time, the new image to fade in.
I know I need to modify the opacity, and I found this great link for "How to make Qt widgets fade in or out": How to make Qt widgets fade in or fade out?
I also know I need to set the image for the QWidget, and I found out how to do that with the following code:
m_image1 = new QWidget();
m_image1->setStyleSheet("border-image: url(\"" + m_imagePath1 + "\") 0 0 0 0 strech strech; ");
Where I'm stuck is the layout. How do I lay a QWidget directly on top of another QWidget.
I did read about QStackedWidget, and it seems like it would be useful: https://doc.qt.io/qt-5/qstackedwidget.html . There's a method to set the current widget via setCurrentIndex(int). However, it doesn't seem to allow me to be transitioning out a widget and transitioning in a widget at the same time. It just either is one widget or the other widget. And from the class description, it says "a stack of widgets where only one widget is visible at a time."
A lot of the layouts I'm aware of, position items next to each other, not on top.
So, my question is how do I stack the widgets to do a transition between the widget contents, by fading them in/out?
Thank you.
What is the most effective way of creating "canvas" with high change frequency in Qt?
Currently I have a main application window (QWidget) where I create a QPixmap and set it to a QLabel:
QPixmap *canvas = new QPixmap(500, 500);
QLabel *area = new QLabel(this);
area->setPixmap(canvas);
The problem is that I have to call area->setPixmap(canvas); after every change I make on the pixmap so that it can be displayed (I'm counting there will be normally several changes every second). Is this way ok? Or is there a better/faster/more efficient solution?
PeterT and Jeremy both have good solutions. Which one is best depends on your needs.
If you are moving items around and changing them, use a QGraphicsScene to store the data you want to display and readily manipulate it. Use a QGraphicsView to display the result.
If you are already doing the rendering elsewhere as a QPixmap and just want to draw the result, subclassing QWidget and drawing it in the paintEvent using QPainter may be simpler. Remember to call update(), though!
Our application uses Qt's Graphics View framework to load the html pages. QGraphicsWebView loads local html page which is black background. But always observed the white screen while launching the application. I have tried setting black background for both QGraphicsView and QGraphicsScene. Nothing worked for me.
Here's the sample code for your reference.
MainWindow which inherited from QMainWindow class
mGraphicsScene = new QGraphicsScene(this);
mGraphicsView = new QGraphicsView(mGraphicsScene);
mGraphicsView->setViewport(new QGLWidget(this));
mGraphicsWebView = new QGraphicsWebView;
mGraphicsWebView->setUrl(QUrl("https://www.google.co.in/"));
mGraphicsScene->addItem(mGraphicsWebView);
setCentralWidget(mGraphicsView);
Is there any way to avoid white screen of the application?
Best Regards,
Pratap
Try next. Why did you see white? Because item already added, but page not loaded, so you see white(blank) item without page. Set to your scene some black pixmap, connect loadFinished signal to special slot, where you add item to your scene. In this case scene will be black, but when page will be loaded, your slot will add this on scnen and you will see only page.
mGraphicsScene = new QGraphicsScene(this);
mGraphicsScene->addItem(new QGraphicsPixmapItem(QPixmap("G:/2/qt.jpg")));
mGraphicsView = new QGraphicsView(mGraphicsScene);
mGraphicsView->setViewport(new QGLWidget(this));
mGraphicsWebView = new QGraphicsWebView;
mGraphicsWebView->setUrl(QUrl("https://www.google.co.in/"));
connect(mGraphicsWebView,SIGNAL(loadFinished(bool)),this,SLOT(slotLoaded()));
//mGraphicsScene->addItem(mGraphicsWebView);
mGraphicsView->resize(1000,700);
mGraphicsView->show();
Slot:
void MainWindow::slotLoaded()
{
mGraphicsScene->addItem(mGraphicsWebView);
}
For example black pixmap which was created by code:
QPixmap black(1000,700);
black.fill(Qt::black);
mGraphicsScene = new QGraphicsScene(this);
mGraphicsScene->addItem(new QGraphicsPixmapItem(black));
When application start:
As you can see, all is black, when page was loaded:
As you can see, it is normal page. It is not very beautiful because I use fast settings and resize window and so on, but you set graphicsview as central widget, do it will be more beautiful.
Thank you very much for the response.
I have tried your solution and also observed white screen while launching the application on Windows
I found the culprit is mGraphicsWebView->setUrl(QUrl("https://www.google.co.in/")); This is blocking all other widgets on the scene. So I have added a singleShot timer and kept this statement under that.
//QTimer::singleShot(100, this, SLOT(loadUrl())); Then it works fine.
Please let me know if you have any better idea.