QT .UI To Display .GIF? - c++

I need some help with my QT .ui source files for my project....I am trying to have a .gif animated image displayed and just looped where I have the property "pixmap" (hashcoinani)...For some reason it is not displaying and I cannot figure out how to make it display with just the .ui files, Any help would be greatly appreciated! hashcoinani is set as a resource in the .qrc file as hashcoin.gif as well.......Im so lost!
<widget class="QLabel" name="coinimage">
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../hashcoin.qrc">:/icons/hashcoinani</pixmap>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="margin">
<number>-2</number>
</property>
</widget>

This can't be done in UI designer. You need to get the animated .gif into a QMovie, and then set that on the label using setMovie. You need some C++ code. The designer only goes so far.
Since both Qt framework and Qt Designer are open-source, you could modify both to provide this functionality. It probably would be a day's job.

Related

QTabWidget Content Not Expanding

Attached is an example of the QT Designer with my issue. My goal is to get any content inside (in particular the lineEdit) to expand to the far right of QTabWidget its within.
If you notice I have the tab selected in the picture and it says there is no layout currently (as indicated by the red no smoking looking symbol on it). When I try to add a layout to it using the buttons above the tabs (for horizontal, vertical, grid, form, etc...), no matter what I do it doesn't change the tabs layout but changes the very top level widgets layout instead which I don't want because that is giving the QTabWidget its ability to take on whatever the size of the window is.
I tried giving a horizontal and vertical layout to the elements within the tab thinking that might work but it didn't work either as my next attached image shows. My hunch is because the tab has no layout, any layouts within will not be honored.
Any help is appreciated. I've spent hours and can't figure it out for the life of me...!
Below is the UI XML:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>xMarket</class>
<widget class="QWidget" name="xMarket">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>737</width>
<height>421</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTabWidget" name="xMarketTabWidget">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Tab 1</string>
</attribute>
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>240</x>
<y>30</y>
<width>113</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>150</x>
<y>30</y>
<width>59</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Search:</string>
</property>
</widget>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Tab 2</string>
</attribute>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
To set the layout on a tab, you first need to select its parent tab-widget.
You can do this either by selecting it by name in the Object Inspector (i.e. by clicking on xMarketTabWidget in your example), or by simply clicking on an appropriate tab in its tab-bar. The parent tab-widget must have a selection rectangle around it before you can set a layout on one of its tabs.
Once you've done that, you can click the Lay Out Horizontally or Lay Out in a Grid button on the Designer toolbar to set an appropriate layout for your tab. But note that a tab must have at least one child widget before you can set a layout on it - the layout buttons will all be disabled for empty tabs.

Setting QScrollArea as central widget in Qt

In Qt I have removed the central widget in an xml editor and replaced it with a QScrollArea, this works when I preview it in QtDesigner:
but when I run the program it looks like this:
Are you not meant to remove the central widget or is there a sizePolicy I have to change?
Here is the ui file:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>179</width>
<height>191</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>224</width>
<height>628</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>75</pointsize>
</font>
</property>
<property name="midLineWidth">
<number>2</number>
</property>
<property name="text">
<string>label
</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>179</width>
<height>19</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
<include location="1.qrc"/>
</resources>
<connections/>
</ui>
Check your ui_mainwindow.h. See if there is a line like:
MainWindow->setCentralWidget(scrollArea);
You can use QMainWindow::setCentralWidget function in your mainwindow.cpp to set a central widget to your main window:
setCentralWidget(myScrollArea);
I don't think there is any way of changing the central widget from the designer.
I am getting proper window when I ran the program with your ui file content. I don't know why it is not creating problem like you have.
I would recommend you to use Qt designer inbuilt in Qt Creator which I felt easier to use.
Also, I think the problem can be one of these:
Generally central widget is good as it provides a base on which you can place all your layouts. So, it is good to have it in your UI.
Here, take care that after inserting widgets into layouts you don't simply break those layouts. The designer will reset the widget width and height. So you have to set them again.
Next, this may have occured if the ui file loaded in designer is not up-to-date while it is changed on disk.
Keep track of all the layouts, the geometry and sizePolicy of widgets.
I won't be able to answer in code since when I used the ui file content which you have given, it doesn't cause problem here.
Create a layout on your mainwindow in which you would put your QScrollArea. This would expand it according to the layout.
P.S. : I open it in Qt Creator.
So please give some more info whether it is fixed when you set the geometry of scrollarea manually.

Qt Checkbox not visible

I have two applications:
Both displays QCheckBox text correctly
Both use the same css stylesheet
All the settings in the widget editor seem to the the same
The check box square is not visible for one application while it is for the other.
Editor view of the QCheckbox.
The application that is working
The application that is not working.
In response to Pavel Strakhov:
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QCheckBox" name="c">
<property name="text">
<string>Display</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="logToFile">
<property name="text">
<string>To File</string>
</property>
</widget>
</item>
</layout>
This issue is cause because there is a global image file used, so the check box will not be visible. I resolve the issue by making a new checkbox image and applied it to all checkboxes in the css.

Setting QLabel pixmap in Qt creator design view

I've set the pixmap field of a QLabel to :/Resources/Logo.jpg in Qt creator design view. As a result the ui file looks like
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>10</x>
<y>0</y>
<width>301</width>
<height>171</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="Utility.qrc">:/Resources/Logo.jpg</pixmap>
</property>
</widget>
From which the following code is generated
label_4 = new QLabel(centralWidget);
label_4->setObjectName(QStringLiteral("label_4"));
label_4->setGeometry(QRect(10, 0, 301, 171));
label_4->setTextFormat(Qt::AutoText);
label_4->setPixmap(QPixmap(QString::fromUtf8(":/Resources/Logo.jpg")));
And although the pixmap is visible in design view it does not appear when I run the application. What am I doing wrong?

QLabel doesn't show pixmap in windows

I've designed a ui in QtDesigner which has a QLabel that must show a JPG image (included in a Qresource file) as pixmap.
The Application works fine in KDE (not tested under gnome), but in windows the image is not shown.
here is the XML code in the ui file which impeliments the QLabel file:
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="lib.qrc">:/image/Yearbook_1970.jpg</pixmap>
</property>
</widget>
</item>