Create Spin Progress bar in Qt, I want to show progress bar like the one which appears while loading. Please Find Image
My code goes like this
QProgressBar *pgbar = new QProgressBar();
pgbar->resize(500,25);
pgbar->setOrientation(Qt::Horizontal);
pgbar->setRange(0,99);
pgbar->setValue(10);
pgbar->show();
installOnDevice(destinationSavePath);
pgbar->hide();
here installOnDevice(destinationSavePath); takes time to process. Currently I am showing Processbar, I dont want to show processbar. Can't I replace with some progress which shows loading image (Rotating) or something similar to that
Have a look at the Twitter Mobile example application. In the file demos/declarative/twitter/qml/twitter/TwitterCore/Loading.qml there is an implementation in QML of the exact thing you want to achieve:
import QtQuick 1.0
Image {
id: loading
source: "images/loading.png"
NumberAnimation on rotation {
from: 0
to: 360
running: loading.visible == true
loops: Animation.Infinite
duration: 900
}
}
Update 1 (reflecting the newly posted code):
Employing QML just for a spinning load indicator in your otherwise Qt Widgets based application seems overkill to me. I would use a QMovie in conjunction with a QLabel to display an animated GIF image containing the spinner:
QMovie* spinnerMovie = new QMovie(":/spinner.gif");
QLabel *spinnerLabel = new QLabel(this);
spinnerLabel->setMovie(spinnerMovie);
spinnerMovie->start();
You should also have a look at the documentation for the Qt Resource System to learn how to bundle images with your application and how to load them.
In order to change the cursor wou have to use the setCursor function or the setOverrideCursor in order to apply it to the application. You can construct any cursor you want using a QPixmap as constructor argument.
In order to achieve an animation effect you will need a QTimer. At every timer event you have to change the cursor's pixmap in order give the feel of animation.
Try Qml Busy Indicator, implemented in pure C++:
http://qt-project.org/wiki/Busy-Indicator-for-QML
Related
This question is a little specific, but I've been unable to find someone with the same problem or a clean solution to the problem.
I'm creating a Qt Quick program, and I want to use a QListView as it appears in QtWidgets. This QtWidgets program has three such views, with checkable items (which is optional: not all QListViews have checkable items).
Because Qt Quick Components doesn't appear to have a QListView equivalent, I set out to make my own from existing components. And the result is ... meh. It looks like this and doesn't exactly behave in the same fashion. Clicking on the text/whitespace of an item checks the item, instead of highlighting it. And the border is just ugly, and doesn't appear in GTK-themed environments. It also doesn't obey custom desktop themes, because the background of the items will always be white.
The code for this custom component is fairly brief, and looks like this:
import QtQuick 2.4
import QtQuick.Controls 1.3
// GroupBox creates a border... most of the time. Not in GTK envs
GroupBox {
id: root
property var model: null
// This wraps the ListView up with a scrollbar
ScrollView {
anchors.fill: parent
ListView { // This is the view component
anchors.fill: parent
model: root.model
// This is the white box that the CheckBox is drawn on
delegate: Rectangle {
width: parent.width
height: box.height
// This is the actual item
CheckBox {
id: box
anchors.fill: parent
text: thing // `thing` is just a placeholder value from the model
}
}
}
}
}
Use a QApplication instead of a QGuiApplication. It will require you to add widgets support (and ship Qt widgets libs). This way, Qt Quick Components will automatically get access to much more system theming like background color in text selection.
Additionally, SystemPalette will provide you with a bunch of native colors that you can use if you want.
Unsatisfying system integration using QGuiApplication:
Nice integration using QApplication:
I have a video output embedded in a QML view. It is working fine, but I want to make that video output go fullscreen when I click on it.
Every time, some images that are in the view (some sibiling, and some not) are visible on top of my video. In fact, it should fill the root element, and be at the front screen.
Changing the z property doesn't do anything.
What is the best trick to make a video go fullscreen? When I switch from normal to fullscreen, the video should continue its flow with no interuption.
A solution only in QML (and no C++) would be preferable, as I build my QMLs by parsing XML files.
You can create new fullscreen window from QtQuick.Window module and pass tpo that window video path,time and play.
Component {
Window{
id: videoWindow
flags: Qt.FramelessWindowHint
HereYourPlayer{
}
}
}
than you should create that Component and call videoWindow.showFullScreen()
I finaly found the solution I needed. In fact it was simplier that it seemed. I created an Item just under the root, and I changed the parent of my video element when I wanted to go fullscreen. I put my new Item as the parent of my video element.
I didnt know that we could change the parent of an element.
I have a QGLWidget that renders an OpenGL scene inside a Qt application. I would like to add some other translucent Qt widgets that are overlaid on top of the QGLWidget. This is more difficult than with standard widgets since the OpenGL drawing context is unknown to Qt's painter classes. So, if I just do the obvious thing and place a transparent toolbar on top of the QGLWidget for instance, the transparent part of the toolbar instead renders black (it doesn't have access to the OpenGL frame buffer when painting).
It seems that the recommended way for handling this sort of thing is to overpaint the 2D content after drawing the OpenGL scene. The linked example seems very straightforward, as long as you're just drawing simple shapes. Instead, what I would like to do is to defer the painting of some child QWidget objects to be done inside the paint event for the QGLWidget.
So, my problem boils down to this:
Prevent the overlay QWidgets from painting in the normal, 2D context.
In the paint event handler for the QGLWidget, paint the overlays after painting the 3D scene that makes up the background.
The second item on this list seems to be simple: I can use QWidget::render() inside the QGLWidget's paint event to draw the desired widgets on top of the viewport. This works just fine.
The first item is more tricky: I need a way to prevent the widgets from painting during the normal course of events and only paint them in the QGLWidget's paint handler. One obvious way to do this is to hide the overlays using QWidget::hide(). This does allow me to paint the widgets atop the OpenGL scene as I would like. However, since the widgets are hidden, they do not respond to mouse or keyboard events. As an example, I'm using a QToolBar with a few buttons on it, and the toolbar is painted properly, but is non-functional (none of the buttons respond to clicks). So, if going down this path, it seems that I would need a way to force the widget to still respond to events even though it is hidden.
Another approach that I've tried is to intercept the QToolBar's paint event using an event filter, with the goal of preventing the toolbar from painting itself. However, the toolbar is still rendered; I'm assuming that this is because the various buttons on the toolbar are child widgets that are still painted, even if I intercept the parent's paint event.
Any ideas on a way that I could accomplish my goal?
I don't understand your issue completely, but I'll try to answer the question stated in the title. You should use event filters. Install an event filter using widget->installEventFilter(object), where widget is a widget you want to block painting, and object is an object of any of your QObject-derived classes. Reimplement eventFilter of this class:
bool MyClass::eventFilter(QObject* object, QEvent* event) {
if (event->type() == QEvent::Paint) { return true; }
return false;
}
When you return true from your eventFilter, the event is filtered and paint doesn't occur.
You can also try to use widget->setUpdatesEnabled(false) to temporarily disable painting. Don't forget to re-enable it when you're done.
I use QtQuick 1.1 and I have an item like this below:
Item {
id: myItem
width: 12345
height: 12345
//...
}
When I run my qml project, it doesn't show any scroll bar for this item (horizental and vertical).
How can i add scroll bar to it? And if I use Qt and QML together (using a QWidget and QDeclarativeView on it), then what's the solution?
Making UI using qml is kind of UI paradigm shift when compared to making desktop widgets. What you are expecting is a normal desktop widget behavior, which is absent in the most mobile platforms UIs. In them, usually, scroll bars are associated with the lists and not with complete pages.
You can however implement that in qml as well. You can have the top element as flickable instead of a rectangle, and the show the scroll bars yourself based on flicks on the page. Try to go through the qml RSSfeed example to understand how you can use combination of flickable and other elements to achieve this.
P.S. : Also, see the qml desktop components introduced in Qt5. They will give you the widget behavior. See if it fits what you want.
But again, you should ask yourself, what exactly are you trying to achieve here ?
Just a quick question.
I'm building my app interface at the moment with Qt.
I set a background image for the mainpage and I use stackedWIdgets to slide from one window to another.
setStyleSheet("background-image: url(:/spherebackground.png);"
"background-repeat: no-repeat;"
"background-position: center center");
When the application starts, a page appears which is made of 3 layouts:
1) One that contains a topToolbar Widget with QPushButtons, and a label displaying the PageTitle
2) in the middle, a mainPageLayout that contains the SlidingStackedWidgets
3) the BottomToolBar
The mainFrameWidget contains a mainFrameLayout:
mainPageWidget=new QWidget();
mainPageLayout=new QVBoxLayout();
//I add the buttons and others
mainPageLayout->addWidget(addEntryButton);
mainPageLayout->addWidget(vocaButton);
mainPageLayout->addWidget(exprButton);
mainPageLayout->addWidget(rulesButton);
mainPageLayout->addWidget(learnButton);
mainPageWidget->setLayout(mainPageLayout);
Then, I have the other pages created with the designer
And then a function that add the pages to the slidingStacked
void MainWindow::createSlidingStackedWidget() {
//the slidingStacked is the Widget that contains the subslidingWidgets
slidingStacked= new SlidingStackedWidget(this);
slidingStacked->addWidget(mainPageWidget);
quickAddView = new QuickAddController(); //which is a UI widget
slidingStacked->addWidget(quickAddView);
}
And then, when a button in the mainLayout is pressed, it triggers a function like this
void MainWindow::slideInAdd(){
topToolBar->clear();
slidingStacked->setVerticalMode(true);
slidingStacked->slideInIdx(1);
setupTopToolBar("Terminer","Ajout Entrée","Modifier");
bottomToolBar->hide();
QObject::connect(goBackButton,SIGNAL(clicked()),this,SLOT(backFromAdd()));
}
The thing is that I'm trying to port an application I created for the IPhone and I want it to have the same "Look and Feel" but when I slide from one page to another...
1) the animation flickers
2) I would like the sliding widgets to be transparent except for the controls (QPushButtons...)
but they have the same sphere background as the one I set up at the beginning of the code
3) My labels and controls also have the same background image when I would like them to be standard
(eg : a label should have a white background)
I can't figure out why...
Hope this will give you a better idea of what's going on...
So far as 2) and 3) go, that is because widgets inherit their parent's palette by default. To fix this, you can explicitly style them, or assign their palette to be the default application palette after they are created. I don't know how to handle the first problem.