Qt Widget Plugin No Output in Designer - c++

I have a group of custom widgets that I am implementing into Qt Designer. I have successfully built the plugin and have been getting both the .lib and the .dll files outputted. I successfully see the list of all my widgets in Qt Designer. However, when I go to drag a widget into the scene, nothing. Nothing on the scene, nothing in the cursor, just nothing at all. I will provide the relevant code of one my widgets and their corresponding plugin. Any help/comment on the matter is greatly appreciated.
EDIT: I have been told to create a MCVE of my project in order to keep it easy to compile and debug. So I have. https://github.com/NickJohn547745/MaterialWidget-MCVE

Never worked with Qt Designer plugins before, but this looked interesting.
Here is what I did to end up fixing your problem. I'm just detailing the method here so that you can understand it and possibly apply it yourself later (the method could apply to other kind of problems you could meet).
As I'm not familiar with Qt Designer plugins, I took Qt example for Designer plugins and made it work on my computer (very easy to do, just compiled, copied the generated .so to QtDesigner plugin's folder).
Then, I took your example from github, compiled it and checked that drag and drop does not work as you reported.
Then, I replaced your QtMaterialBadgePlugin by a renamed copy of Qt's AnalogClockPlugin and your QtMaterialBadge by a renamed copy of Qt's AnalogClock. Then I compiled the plugin, and , surprise....I could drag and drop the plugin item, it worked! So there was definitely something wrong with your code.
Then I replaced back the "renamed copy of Qt's AnalogClock" with your original QtMaterialBadge class and, new surprise...drag and drop still worked in Qt Designer. Conclusion: there is definitely something wrong with your QtMaterialBadgePlugin!
So I checked the differences between your QtMaterialBadgePlugin class and Qt's AnalogClockPlugin class. That was simple as there's only few lines of code...
Just replace:
QString QtMaterialBadgePlugin::domXml() const
{
return QLatin1String("<widget class=\"QtMaterialBadge\" name=\"qtMaterialBadge\">\n<widget>\n");
}
by:
QString QtMaterialBadgePlugin::domXml() const
{
return "<ui language=\"c++\">\n"
" <widget class=\"QtMaterialBadge\" name=\"qtMaterialBadge\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>100</width>\n"
" <height>100</height>\n"
" </rect>\n"
" </property>\n"
" </widget>\n"
"</ui>\n";
}
And now your plugin will be draggable and droppable from Qt Designer. Note that you forgot:
the top level's "ui" XML node, but that's apparently optionnal as the plugin works even without that
the geometry property (which is used to determine the default size used during drag and drop). That was the root cause of your problem!
Now, you'll see drag and drop only shows a gray square area (while Qt example shows a preview of the AnalogClock), you'll probably prefer to have a preview of your widget here, and I'll let you work this out. I suppose my answer is enough considering your question "However, when I go to drag a widget into the scene, nothing. Nothing on the scene, nothing in the cursor, just nothing at all": Now you get something!

Related

Qt - Display animated GIF selected by QListWidget on MainWindow

thank you in advance for reading and help.
I'm trying to make a GIF manager based on a QListWidget where you can select a GIF from the list (using on_*_itemClicked, as you can see below) and it will appear the animated GIF in the space below the list (or sideways, doesn't matter).
void MainWindow::on_listOfURL_itemClicked(QListWidgetItem *item)
{
QLabel* lab = new QLabel(this);
QMovie* mov = new QMovie(":/res/giftest/C:/Users/Rober/Desktop/giftest.gif");
lab->setGeometry(200, 200, 200, 200);
lab->setMovie(mov);
lab->show();
mov->start();
}
GUI screenshot of the program
I've tried using the piece of code above, but it shows nothing. It is just a futile try of making it work, that's why the GIF path is the same, you needn't worry about it.
Honestly, I've search a lot of code in forums and this very website regarding GIFS and animations, and none of the things I've seen have worked for me.
How should I proceed? I guess I should use some graphics QWidget in the UI and link it with the function on_*_itemClicked so it takes the location of the image from the QListWidgetItem and displays where I pointed in the UI.
I've gotten the code pasted here by surfing the Mighty Google, and it brings me some doubts:
I create a QLabel with the MainWindow as parent. Okay, but where will it appear?
Can't I create in the Designer a widget that I can define where will it be and just make the GIF work?
I think I've explained myself correctly, if not just let me know.
EDIT: I think what I need is a QLabel that is inside the MainWindow, below the URL list. How do I shape that QLabel in QtDesigner and then take that same QLabel in code and manipulate it with the GIF?
I think, you need to include into .pro
QTPLUGIN += qgif
and show label->show();
Of course you can add things in designer. You can add custom widgets you create, but you need make special project that would make a "plugin" for Designer and build it in Release mode, then install plugin in proper plugin folder.
For that you should be sure, that those are added to .pro file:
CONFIG += plugin
TEMPLATE = lib
QT += widgets uiplugin
Then you need to declare and implement plugin derived from QObject AND QDesignerCustomWidgetInterface.
DO CHECK validity: mov->isValid() Code that relies on external sources being good eventually becomes source of little disasters. Program either need a plugin's .dll next to it or static plugin linked with it
When you installed Qt, you installed app called QtAssistant. Take advantage of it. It's great deal of help. as well as their forums and examples storage you got in Qt directory. Qt5 got plugin example online: http://doc.qt.io/qt-5/qtwidgets-tutorials-widgets-childwidget-example.html
Okay, I've found myself the answer. It was pretty silly actually:
I didn't realize I could select a QLabel created in QtDesigner using ui->label and manipulate it.
ui->label->setMovie(selectedGif);
selectedGif->start();
ui->label->show();
Novice mistakes...

Qt: QVideoWidget doesn't show up and disables all buttons within application OR extremely slows down the application

To make it clear the question is: Why, when I add a QVideoWidget to my application, all buttons become not clickable, the scrollbars don't work, and the comboboxes as well become not clickable? Is QVideoWidget disabling those functionalities? Or is that maybe (like I read in this SO question) QVideoWidget is extremely slowing down my application, just by being added to the application?
Now the details:
I really hope someone can help me with this. I'm trying to place a QvideoWidget into my desktop application with the following code (nothing special, just like in the tutorials):
// ...
// more code above for other things...
// main video-player widget
video_widget = new QVideoWidget;
video_widget->setMaximumHeight(100); // I could set any size here...this is not the point
video_widget->setMinimumHeight(100);
video_widget->setStyleSheet(STYLE_WIDGET_BG); // same background as the other widgets...
video_widget->setMaximumWidth(100);
video_widget->setMinimumWidth(100);
media_player = new QMediaPlayer(0, QMediaPlayer::VideoSurface);
TV_V_LAYOUT_MAIN_2->addWidget(video_widget); // #define TV_V_LAYOUT_MAIN_2 ui.lvl_4_tv2_h_1 --> this a layout inside another layout...
media_player->setVideoOutput(video_widget);
return; // this function is called inside the MainWindow constructor
So there are the situations:
1) Without adding the videowidget, everything works fine...
2) As soon as I add the QVideoWidget with the code above:
app overview
What happens?
The video player doesn't show up in any way. There should be at least the gray background like the other widgets, but nothing. Yet the buttons position lowers, so I guess the player was inserted...The problem is: all buttons (and I mean ALL buttons within my application) are disabled. So are the comboboxes and the scrollbar. By disabled I mean, when you click them, it doesn't normally "animate" like when a button is cliked, and the scrollbar doesn't scroll...
By the way the QVideoWidget is not places into the same layout as the buttons below. You can see the layout hierarchy here: Layouts with Qt Designer
I guess I'm missing something very simple. Anyone got the solution for me?
INFO: I'm programming with Visual Studio 2013 with Qt Add-In; I use only standard libraries; gstreamer is included in the project as well (nothing implemented yet).
OLD EDIT: it may be that the inserting of the video-widget extremely slows down the application, therefore giving the illusion that the scrollbar and the buttons don't work, just because it takes a lot of time for them to process the user interaction. Is this possible? Any solution for that?
Got the solution:
If your QVideoWidgets or QMediaPlayers extremely slow down your application, all you have to do, if you haven't yet, is to move all (or just the nedeed) Qt dll's into your project folder.
That's very basic, I know, yet that was my problem. Now it works like heaven.

How to add the OS X flavor to a Qt app

I have used Qt previously only in the form of PyQt, and today I tried the original version of Qt in C++.
I got it working, however, when if start up my app, I have several problems with it:
it's stationary, which means, I cannot drag it across the screen
I cannot change the size of the window
it does not have a OS X type status bar (which contains the three colored buttons and the name of the window)
How can I add these features to my C++ Qt app?
I have tried to look for a solution, but only found QtApplication::setStyle();, which did not solve my problem.
You can see the code here.
The code inside your subclass of QMainWindow contains this line:
setWindowFlags(Qt::FramelessWindowHint);
That is probably causing most of the problems you describe. Try removing that line.

Qt5 - Porting a Video Player from 4.8 to 5.1

I'm working on migrating my code from Qt 4.8.4 to Qt 5.1.1 and seemed to have run into a peculiar problem. Previously I was using the Phonon library's video widget to allow users to interact with the video. Since Phonon is no longer supported I was looking for a way to replace my Phonon widget via the Qt Designer but I found no replacement widget available. Does anyone know how we're supposed to go about porting this functionality?
If anyone has any insight, it is appreciated as always!
All the other answers provide very useful information, but since I was looking for a specific and functional implementation, I'm guessing people that stumble on this may be looking for one as well, so I'll post my code along with my thought process and a bit of background info of my setup.
videoWidget = new QVideoWidget;
player = new QMediaPlayer;
verticalLayout->addWidget(videoWidget);
player->setVideoOutput(videoWidget);
player->setMedia(QUrl::fromLocalFile("Resources\\videos\\example.m4v"));
videoWidget->show();
player->play();
So to go through this, basically in my project I have a widget that is a part of a stackwidget structure on which I have some QWidgets like playback control buttons, labels, etc, and I previously had my Phonon video player. I really really didn't want to generate it all programatically so I managed to find a solution.
The above code was located in this container widgets constructor. In the designer I have made a simple, empty verticalLayout, positioned and sized it to my liking. This allowed me to embed the QVideoWidget despite not having a interactive QWidget in the Designer. videoWidget, and player are declared as private in the container widget's header file.
You've already noted there's no more Phonon
Now what you've got is QtMultimedia and the QtMultimediaWidgets. If you want them available to your project and you're using Qmake, then change your QT line in your .pro file from something like:
QT += widgets
to:
QT += widgets multimediawidgets
That won't do anything about the designer interaction, though. I think it's probably a matter of no one having done the work to make a custom widget extension for QVideoWidget.
If that's correct, then if you want to place a QVideoWidget into your form via Qt designer you will have to use "Widget Promotion". Just put an ordinary QWidget into your layout, and then right click on it in the form and pick Promote to ...
As for the specifics of porting Phonon abilities to the new widgets, I dunno what's covered and what isn't. No answers here yet, either:
How to port Qt4.6 Phonon based media-application to Qt 5.1?
It seems that although Qt itself no longer includes Phonon, there is a Qt5 port available as an external library:
http://community.kde.org/Phonon/Releases/Core/4.7.0
Alternatively, you can switch to the new QtMultimedia APIs:
https://qt-project.org/doc/qt-5.1/qtmultimedia/videooverview.html

Qt Creator 2.8.1 Qt 5.1.1 Qt Designer Linux Show a new Form

I am a beginner with Qt - so hopefully this will be an easy question to answer. I have a reasonable amount of experience with C++, that part is not a problem
The purpose of my application is to do code generation, initially to make header & implementation files for classes. I quite like the Class wizard on Code::Blocks, but I reckon I can do a lot more.
I have a main Widget which has a tabWidget & some lineEdit's & some pushButtons. To preview what will eventually be in the file, I have created a new Form, with a TextBrowser in it. The new Form entry appears in the .pro file.
I would like to have the new Form displayed when I press the pushButton, & I am intending to write text in the TextBrowser based on the contents of the lineEdit's in the main Widget.
I have been looking through the documentation all afternoon, but most of the examples show either a main widget or a Form by itself. I have seen the example of the Class Wizard (which is nearly what I want to do), but I would rather a tabWidget interface. Being able to open a Form from a button is a pretty basic thing to be able to do.
For some reason, the examples page in my QtCreator help doesn't show any examples - previous versions had heaps of examples. Not sure why that is.
Do I have my terminology mixed up - should I have a Dialog rather than a Form? Not sure what the difference is.
Apologies in advance if all this is in the documentation somewhere, I seem to spend hours trolling through it, so maybe someone could provide some links - that would be great.
Suppose the new form you created along with with header and cpp file is mynewform.h, mynewform.cpp and mynewform.ui
Now include mynewform.h in your mainwindow class,
and create an object of the class
mynewform myform;
In the clicked slot of pushbutton just type:
myform.show();
or
myform.exec(); //(if you want a blocking call)