Python Load module in parent to prevent overwrite problems - python-2.7

I'm building a QGIS plugin with Python and designed a GUI for it. I can compile it with pyuic4, but on load it gives an error. I found out that I can prevent that error by adding the line below in the compiled Python code. Only at some moments I have to recompile and so the file gets overwritten and the line is lost.
form.py
from qgis.gui import QgsMapLayerComboBox
I have a 'parent' file which imports the compiled version like so:
dialog.py
from form import Ui_Dialog
Is there some way to import the QgsMapLayerComboBox in dialog.py so I don't have to add it every time to form.py after I recompiled my GUI?
EDIT:
<widget class="QgsMapLayerComboBox" name="mMapLayerComboBox">
<property name="geometry">
<rect>
<x>100</x>
<y>18</y>
<width>160</width>
<height>22</height>
</rect>
</property>
<property name="filters">
<set>QgsMapLayerProxyModel::RasterLayer</set>
</property>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>QgsMapLayerComboBox</class>
<extends>QComboBox</extends>
<header>qgsmaplayercombobox.h</header>
</customwidget>
</customwidgets>

Open your form.ui with some text editor and replace:
<customwidget>
<class>QgsMapLayerComboBox</class>
<extends>QComboBox</extends>
<header>qgsmaplayercombobox.h</header>
</customwidget>
with
<customwidget>
<class>QgsMapLayerComboBox</class>
<extends>QComboBox</extends>
<header>qgis.gui</header>
</customwidget>
and compile again.

Related

deploy gtkmm2 application to windows - fonts not rendering out of mingw terminal

I have run into peculiar problem. Did a lot of research but cannot find even a hint what can I try to do to fix the problem.
What I did is to write a very simple example that uses glade to render application main view. I tried this on Linux ubuntu and then planned to port the code to Windows using msys2 and mingw32. Example is written in GTKmm2 (C++ GTK2 (not GTK3)) After a lot of struggle to port I have managed to compile example under windows.
Result is as follows (since it is hard to describe I include picture):
https://imgur.com/WkoiN3v
This is how it looks when application is started from mingw32 terminal window.
Now, I try to 'export/deploy' the app in another part of windows where I intended to use it. Basically trying to make POC of deployment.
After ordial of finding all relevant .dlls and supporting files in deployment application starts but fonts are not rendering properly.
When I run app from windows command line I get this:
https://imgur.com/PWZloIr
I tried to toy with ~/.gtkrc-2.0 (as previously using it for python gtk+) and try to set default gtk font to something available in windows, but it seem not to have any effect on font rendering.
What else I can try to do ?
As suggested ... Code:
main.cxx
// #include <gtkmm.h>
#include <gtkmm-2.4/gtkmm.h>
Gtk::Window* window;
static void on_q_button_clicked()
{
if(window)
window->hide(); //hide() will cause main::run() to end.
}
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create_from_file("basic.glade");
builder->get_widget("window1", window);
Gtk::Button* pButton = 0;
builder->get_widget("button1", pButton);
if(pButton)
{
pButton->signal_clicked().connect( sigc::ptr_fun(on_q_button_clicked) );
}
Gtk::Main::run(*window);
return 0;
}
basic.glade
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<property name="default_width">440</property>
<property name="default_height">250</property>
<property name="destroy_with_parent">True</property>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Yes!
Always
This is just a text</property>
<property name="justify">center</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">click me to close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
that's about all source that there is. It's a kind of 'hello world' code just to test concept end to end, before writing intended application.
I managed to get font rendering working, by some lateral thinking, but I am still puzzled what to do.
Due the specifics of the setup (enterprise constrains) I thought that USERPROFILE or HOMEDRIVE or HOMEPATH are playing a role (because of ~/.gtkrc-2.0 settings). But it turned out that it is not making any influence.
Font rendering comes correct when I add path to mingw32 bin folder. So:
SET path=C:\path\to\mingw32\bin;%path%
Then, application shows fonts properly. I believe that after this intervention, font settings in ~/.gtkrc-2.0 start working too.
However, this still do not make full deployment to the target machine proper, as I still do not know what file (dynamic library or
executable) is needed from \mingw32\bin folder to render fonts at
the target. I would like not to be dependent on installing mingw at
the target machine just for the sake of running the application.
But it is a step forward :)
Update:
figured out 2 more libraries expected to be included in deployment, but still not enough to fix the font issue. Following libraries shall be reachable by main.exe that are found in bin folder:
libgdk-win32-2.0-0.dll
libgtk-win32-2.0-0.dll
full list of dynamic libraries that shall be accessible is:
libatk-1.0-0.dll
libatkmm-1.6-1.dll
libbz2-1.dll
libcairo-2.dll
libcairomm-1.0-1.dll
libffi-6.dll
libfreetype-6.dll
libgcc_s_dw2-1.dll
libgdk-win32-2.0-0.dll
libgdkmm-2.4-1.dll
libgio-2.0-0.dll
libgiomm-2.4-1.dll
libglib-2.0-0.dll
libglibmm-2.4-1.dll
libgobject-2.0-0.dll
libgraphite2.dll
libgtk-win32-2.0-0.dll
libgtkmm-2.4-1.dll
libharfbuzz-0.dll
libiconv-2.dll
libintl-8.dll
libpango-1.0-0.dll
libpangomm-1.4-1.dll
libpcre-1.dll
libpixman-1-0.dll
libpng16-16.dll
libsigc-2.0-0.dll
libstdc++-6.dll
libwinpthread-1.dll
zlib1.dll
And, confirmed: styling, font selection and font size user customization works from ~/.gtkrc-2.0 properly when path is set.
( For people who do not get unix idioms '~/' means your user folder. On windows (e.g. windows 7) this will be c:\Users\YourWindowsUserName therefore customization file on windows is: c:\Users\YourWindowsUserName.gtkrc-2.0 )

How to dynamically swap QWidgets

I have a QMainWindow which contains, on the left, a QTreeWidget and, on the right, another QMainWindow with windowFlags set to Qt::Widget.
This is because the QMainWindow is the only way to provide docking functionality to a QWidget. (I want the docked components to be popped out of the "real" window entirely if needed.
My problem is that I want users to be able to keep popped out dock widgets even if their item is not selected on the left.
For example, here is the global layout:
Let's say I select Item 1. On the right I will have some dockable widgets which I am able to reorder as I wish. If I pop one out to keep an eye on it, I don't want it to disappear if I select Item 2.
To go even further, I could want to show ALL Items' dockable widgets at once if I want.
My original idea to achieve this was to make each Item have its dedicated QMainWindow stored inside its data and I would just switch the right one to reflect the currently active one.
Maybe what I want is a bad idea and maybe it's not even feasible.
Could someone with some Qt knowledge tell me if I'm doing/wanting something wrong please?
Edit:
It would be perfectly fine to me if there were a way to trigger the "inner QMainWindow" pop out manually. Like, for example, a button "pop out" in the top right corner which would completely pop it and make it an entirely new window (still linked to the other one, though)
Edit2:
I's like to point out that I haven't tried anything regarding this question yet. I am essentially wondering if it fits with Qt's way of doing things.
This question made me happy about being able to provide docking capabilities to only a part of the program but I still aren't sure about what I want. Can I really achieve this?
Edit7, MVCE:
Hopefully I didn't forget anything since this is done by modifying my files.
mainwindow2.cpp
#include "mainwindow2.hh"
#include "ui_mainwindow2.h"
#include <QTreeWidgetItem>
MainWindow2::MainWindow2(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow2)
{
ui->setupUi(this);
ui->mainPanel->setWindowFlags(Qt::Widget);
QTreeWidgetItem* item = new QTreeWidgetItem;
item->setData(0, 0, QVariant::fromValue(QString("Item 1")));
ui->accountsTreeWidget->addTopLevelItem(item);
QTreeWidgetItem* item2 = new QTreeWidgetItem;
item2->setData(0, 0, QVariant::fromValue(QString("Item 2")));
ui->accountsTreeWidget->addTopLevelItem(item2);
}
MainWindow2::~MainWindow2()
{
delete ui;
}
mainwindow2.hh
#ifndef MAINWINDOW2_HH
#define MAINWINDOW2_HH
#include <QMainWindow>
namespace Ui {
class MainWindow2;
}
class MainWindow2 : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow2(QWidget *parent = 0);
~MainWindow2();
private:
Ui::MainWindow2 *ui;
};
#endif // MAINWINDOW2_HH
mainwindow2.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow2</class>
<widget class="QMainWindow" name="MainWindow2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1200</width>
<height>700</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>1200</width>
<height>700</height>
</size>
</property>
<property name="windowTitle">
<string>Main Window</string>
</property>
<widget class="QWidget" name="centralWidget">
<property name="minimumSize">
<size>
<width>1200</width>
<height>658</height>
</size>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1" rowspan="2" colspan="2">
<widget class="QMainWindow" name="mainPanel"/>
</item>
<item row="0" column="0">
<widget class="QTreeWidget" name="accountsTreeWidget">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<height>16777215</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectItems</enum>
</property>
<property name="uniformRowHeights">
<bool>true</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<connections/>
</ui>
main.cpp
#include "mainwindow2.hh"
#include <QApplication>
#include <QStyleFactory>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
app.setStyle(QStyleFactory::create("Fusion"));
MainWindow2 w;
w.show();
return app.exec();
}
project.pro
#-------------------------------------------------
#
# Project created by QtCreator 2017-11-12T23:07:49
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = project
TEMPLATE = app
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
INCLUDEPATH += $$PWD
SOURCES += \
main.cpp \
mainwindow2.cpp
HEADERS += \
mainwindow2.hh
FORMS += \
mainwindow2.ui
In the right side, you could add a parent widget, with a QBoxLayout, attach all the items to it, and just hide, show and sort them as you wish.
Make them a custom class, with a public int variable to let you identify them later on. Store their pointers in a QList, and then just loop the list and hide or show items by your criteria ( Using the int variable ).
Example:
Items form category A -> int value 0
Items form category B -> int value 1
etc...

Why QSpinBox jumps twice the Step value

I have a simple python qt application in which I want to plot something dynamically via matplotlib. I was trying to follow instructions like this and that. It works as expected except for one thing, my spinbox updates twice upon mouse click and I do not understand why. Well, during the development the valueChanged.connect() worked fine until I got to a certain point. Then the update_figure() was called twice and the displayed value jumped by two instead of the desired one. I tried to make a minimum working example, you find below. Without the sleep command in update_figue my spinbox behaves normal, with sleep it is called twice and the value jumps by two, with an delay given by sleep.
Why does the sleep in update_figure influence the spinbox, or what is happening here? Is it the way I constructed the connect()?
BTW: I observed the same behaviour on a slider.
Cheers
(I do not think it matters, but this is on openSuse Leap)
EDIT: I could make the example even "more minimal".
from PyQt5.uic import loadUiType
from PyQt5.QtWidgets import QApplication, QMainWindow
import sys
from time import sleep
Ui_MainWindow, QMainWindow = loadUiType('main.ui')
class Main(QMainWindow, Ui_MainWindow):
def __init__(self, ):
super(Main, self).__init__()
self.setupUi(self)
self.spinBox_dac.valueChanged.connect(self.update_figure)
def update_figure(self):
##### The following line makes the difference!
sleep(1) #####################################
##### why?
print "damn...once or twice?"
return
if __name__ == '__main__':
app = QApplication(sys.argv)
main = Main()
main.show()
sys.exit(app.exec_())
Here is the main.ui:
<?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>185</width>
<height>107</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>1100</width>
<height>905</height>
</size>
</property>
<property name="windowTitle">
<string>mini</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QSpinBox" name="spinBox_dac">
<property name="geometry">
<rect>
<x>80</x>
<y>40</y>
<width>61</width>
<height>28</height>
</rect>
</property>
<property name="minimum">
<number>3</number>
</property>
<property name="maximum">
<number>20</number>
</property>
<property name="singleStep">
<number>1</number>
</property>
<property name="value">
<number>4</number>
</property>
</widget>
</widget>
</widget>
<resources/>
<connections/>
</ui>
The sleep() call prevent qt to process the mouse-release and the QSpinBox "thinks" that the mouse is pressed long enough to increase/decrease the value again (auto-repeat).
See https://bugreports.qt.io/browse/QTBUG-33128
A solution could be:
def update_figure(self):
for _ in xrange(10):
QApplication.processEvents()
sleep(0.1)
print "Only once :-)"
Anyway it's not a good practice to block the UI while performing long operations, the work is usually delegated to another thread.
EDIT
This affect Qt4 and Qt5 both, but it behave a bit differently.
There is no setAutoRepeat because in the QAbstrectSpinBox this behavior is implemented using styles, while in QAbstractButton is implemented with a timer.
The way around this is to create a ProxyStyle and set a very long "auto-repeat" interval
from PyQt5.uic import loadUiType
from PyQt5.QtWidgets import QApplication, QMainWindow, QProxyStyle, QStyle
import sys
from time import sleep
Ui_MainWindow, QMainWindow = loadUiType('main.ui')
class CustomStyle(QProxyStyle):
def styleHint(self, hint, option=None, widget=None, returnData=None):
if hint == QStyle.SH_SpinBox_KeyPressAutoRepeatRate:
return 10**10
elif hint == QStyle.SH_SpinBox_ClickAutoRepeatRate:
return 10**10
elif hint == QStyle.SH_SpinBox_ClickAutoRepeatThreshold:
# You can use only this condition to avoid the auto-repeat,
# but better safe than sorry ;-)
return 10**10
else:
return super().styleHint(hint, option, widget, returnData)
class Main(QMainWindow, Ui_MainWindow):
def __init__(self, ):
super(Main, self).__init__()
self.setupUi(self)
self.spinBox_dac.setStyle(CustomStyle())
self.spinBox_dac.valueChanged.connect(self.update_figure)
def update_figure(self):
sleep(1)
print "Only once!"
if __name__ == '__main__':
app = QApplication(sys.argv)
main = Main()
main.show()
sys.exit(app.exec_())

(Help) Is there any way to activate a Gtk.Switch, detect an exception, and then de-activate it programatically?

Mainly that's the question here. In a previous attempt I tried to accomplish this by making some funcs, activating and de-activating a switch, etc, but with no good results.
You can see my previous question here:
Previous question here on StackOverflow
I want to do this:
User runs program --> Tries to activate Switch --> Program detects exception --> Don't close entire program, just deactivate switch again as if user hadn't touched it
My previous code was able to accomplish only when the switch was "Off".
I want this to work in both states (ON & OFF)
If user wants to turn switch OFF (It Was ON), and program detects an exception, turn switch ON automatically again, like if nothing happend & vice versa
I'm using Python2.7, Glade to design GUI, Gtk 3.4 and Ubuntu 14.04.5 as my OS
In this new question I'm asking for some help solving this.I've done research and I've wrote code earlier, but MY code won't work at all. (You can see it in my previous Question)
I need someone to contribute with some new piece of fundamental code just to make this work, because I've tried all I know and just nothing.If you're asking yourself why I didn't provide any code, it's because I'm trying to force people to answer totally new pieces of code.
Why? Maybe because my previous code was kinda faulty, or something that maybe was blocking it. I'M NOT ASKING PEOPLE TO WRITE DOWN MY ENTIRE PROGRAM, in fact this isn't the entire program, it's just a tiny piece of it
Thanks anyways.
EDIT: Here's my actual code
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
import os
import subprocess
import sys
import subprocess
import signal
import time
from subprocess import call
import threading
from multiprocessing import Process
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GdkPixbuf
builder = Gtk.Builder()
#builder.add_from_file("""./Testing2.glade""")
builder.add_from_string("""
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.16.1 -->
<interface>
<requires lib="gtk+" version="3.2"/>
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<property name="halign">baseline</property>
<property name="valign">baseline</property>
<property name="title" translatable="yes">Test</property>
<property name="resizable">False</property>
<property name="window_position">center</property>
<property name="icon_name">applications-accessories</property>
<property name="urgency_hint">True</property>
<property name="has_resize_grip">False</property>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="margin_left">24</property>
<property name="margin_right">24</property>
<property name="margin_top">24</property>
<property name="margin_bottom">24</property>
<property name="orientation">vertical</property>
<property name="spacing">16</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkEntry" id="entry1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="primary_icon_name">applications-games</property>
<property name="placeholder_text" translatable="yes">Texto</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="switch1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">center</property>
<property name="valign">center</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
""")
window1 = builder.get_object('window1')
textie = builder.get_object('entry1')
switchie = builder.get_object('switch1')
def TurnOn(switch, active):
print switchie.get_active()
if yay == "":
switchie.set_active(not switchie.get_active())
def TurnOff(switch, active):
print switchie.get_active()
if yay == "":
switchie.set_active(not switchie.get_active())
def ParentTrue(switch,active):
yay = textie.get_text().rstrip()
if yay == "":
def Hi():
print switchie.get_active()
switchie.handler_block(connecting)
switchie.set_active(False)
switchie.handler_unblock(connecting)
return True
Hi()
def ParentFalse(switch,active):
yay = textie.get_text().rstrip()
if yay == "":
def Hi():
print switchie.get_active()
switchie.handler_block(connecting)
switchie.set_active(True)
switchie.handler_unblock(connecting)
return True
Hi()
switchie.set_active(True)
def qck():
while True:
os.environ["SomeVar"] = str(switchie.get_active())
p1 = threading.Thread(target=qck)
p1.start()
if not os.environ["SomeVar"]:
connecting = switchie.connect('notify::active', ParentFalse)
if os.environ["SomeVar"]:
connecting = switchie.connect('notify::active', ParentTrue)
window1.set_position(Gtk.WindowPosition.CENTER)
window1.connect("delete-event", Gtk.main_quit)
window1.show_all()
if __name__ == '__main__':
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
Gtk.main()
This code just works from OFF to ON. It won't work when you change from ON to OFF
Example:
If I execute this code, and try to activate switch WITHOUT entering text first, It won't change, BUT if you enter text (It doesn't matter, just enter a single letter if you want) it will allow you to move the switch from OFF to ON. Unfortunately It won't do anything special if you want to move switch from ON to OFF even if you try to do so without entering text first

Qt - Using QUiLoader to load a widget with no parent

I have just started learning Qt and I am trying to create a simple widget using this QUiLoader. But I am getting this error : "Designer: An error has occurred while reading the UI file at line 1, column 0: Premature end of document."
#include <QtGui/QApplication>
#include <QtUiTools/QUiLoader>
#include <QFile>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QUiLoader loader;
QFile file(":/aks.ui");
file.open(QFile::ReadOnly);
QWidget *myWidget = loader.load(&file);
if(myWidget){
myWidget->show();
}
return a.exec();
}
I constructed the ui file using QtCreator 2.4.1 and I am on Qt 4.7.4. Check out the ui file too.
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>131</width>
<height>129</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>A</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_2">
<property name="text">
<string>B</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_3">
<property name="text">
<string>C</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_4">
<property name="text">
<string>D</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_5">
<property name="text">
<string>E</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
My project file:
#-------------------------------------------------
#
# Project created by QtCreator 2012-05-21T19:48:31
#
#-------------------------------------------------
QT += core gui
TARGET = Example
TEMPLATE = app
SOURCES += main.cpp \
sortdialog.cpp
HEADERS += \
sortdialog.h
FORMS += \
sortdialog.ui \
aks.ui
CONFIG += uitools
You need to add your .ui file to the resources of your project. Resources are files which get "compiled inside" of your app and are then available to Qt classes by file paths starting with ":/".
In order to add resources to your project, you need to create a resource file listing the files you want to register as resources. This file will be another XML file and can be created and edited by QtCreator. In the project manager, add another file and select the type Qt -> Qt resource file from within the dialog.
In your .pro file then appears a section:
RESOURCES += \
resources.qrc
In the resource file you need to add a prefix; just name it / (or leave it empty). Within this prefix you can add the file aks.ui so it will be named :/aks.ui.
Note that this type of UI creation takes place in runtime. That means, it is more flexible (maybe the ui file gets created only at runtime), but a little bit slower (since parsing and some more runtime processing takes place).
If you're new to Qt, you probably don't know that you can also let Qt create a class file for your ui file in the build process. This is already done when you list your ui file in the pro file in the FORMS += section.
To use the automatically built class, you should also have created a designer form class, which is another class where you put your own code inside. This class will load the automatically built class to setup your ui.
So there are two classes:
* The automatically generated class for your ui file, called Ui::Aks (in a namespace Ui), found in the file ui_aks.h in the build folder.
* Your own wrapper class; the acutal widget class, which uses the ui class.
If you want to create the second class manually, you can write (QtCreator actually does exactly this step when you add a designer form class instead of only a designer form):
aks.h:
#ifndef AKS_H
#define AKS_H
#include <QWidget>
namespace Ui {
class Aks; // <-- this is the automatically created ui class which we need
}
class aks : public QWidget // <-- your own widget class using the designer UI
{
Q_OBJECT
public:
explicit Aks(QWidget *parent = 0);
~Aks();
private:
Ui::Aks *ui; // <-- instance of the automatically created ui class
};
#endif // AKS_H
aks.cpp:
#include "aks.h"
#include "ui_aks.h" // <-- include the automatically generated ui class
Aks::Aks(QWidget *parent) :
QWidget(parent),
ui(new Ui::Aks)
{
ui->setupUi(this); // <-- here, the widgets from the ui file get created
}
Aks::~Aks()
{
delete ui;
}