spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » QT » Page 1
How to set the cursor for a header in a QTreeWidget in PySide?
Hacky way, but you could do this by casting self.header() into a QWidget, since setCursor() is a method of QWidget class. import sys from PySide import QtCore, QtGui class Tree(QtGui.QTreeWidget): def __init__(self, parent=None): super(Tree, self).__init__(parent=parent) QtGui.QWidget(self.header()).setCursor(QtCore.Qt.WaitCursor) widget = Tree() widget.show() And you

Categories : Qt

Why does all selected QGraphicsItem not receive mouseMove event?
From your description I would not handle these actions in MyCustomItemClass::mouseMoveEvent because this is only executed when the mouse moves on top of that particular item as you already stated. Instead I'd subclass the mouseMoveEvent in the scene to check which items are selected and execute the related method in these items. Of course you have to be careful to only move them relatively to the

Categories : Qt

Connect to PostgreSQL server with "cert" authentication method using QSqlDatabase
I need to pass my certificates to the server. There's no function in Qt for that because there's no equivalent function in libpq for that either. It happens automatically, as described in Client Certificates inside SSL support from libpq documentation Excerpt: If the server requests a trusted client certificate, libpq will send the certificate stored in file ~/.postgresql/postgresql.c

Categories : Qt

How to implement custom boolean widget for use with QDataWidgetMapper?
QDataWidgetMapper prefers to use the property with USER true for its mapping but there already one called checked in QAbstractButton use that property instead. You may need to call isCheckable(true) in the constructor;

Categories : Qt

How to make tab's item to be created programmatically?
Every tab in TableView is represented by a Tab component that inherits from Loader component. If you want force the Tab to load its contents, just set active property to true. This property controls when the component must be loaded. So now, your button code looks like this: Button{ text: "add tab" onClicked:{ var c = Qt.createComponent("Tab.qml"); tabview.addTab("tab", c)

Categories : Qt

Dimensioning in Qt
You can use something like this to get the length in inches: qreal distance(QPointF & p1, QPointF & p2) { return QLineF(p1, p2).length() / QApplication::screens().at(0)->physicalDotsPerInch(); } Multiply by 2.54 if you want centimeters. Then create a QGraphicsItem which draws the line between the two points and text with the distance. You can use void QWidget::mousePress/Releas

Categories : Qt

How to reload Page in blackberry cascades QML
Obviously, there are some part of code missing as you show us a Page but you seem to push a new page from a NavigationPane. Add this to your NavigationPane : onPopTransitionEnded: { fetchInfo() }

Categories : Qt

Bind to imported Javascript property
Generally, you can't bind QML property to variable from pure JavaScript module. My advice is to use lightweight QML alternative - QtObject . You can add custom set of properties and signals to it, for example: QtObject { id: mySettings property string iconPath: "./icon.png" } This properties can be binded later exactly as you want.

Categories : Qt

Styling Treeview Qt Show Number of Elements
You need to use QIdentityProxyModel and override data method. Pseudo-code: int MyProxyModel::myFileCount(const QModelIndex &index) { return 42; // You code here } QVariant MyProxyModel::data(const QModelIndex &index, int role) { const QVariant orig = QIdentityProxyModel::data(index, role); switch (role) { case Qt::DisplayRole: return QString("%1 (%2)").arg( orig.toString()

Categories : Qt

call QML function from C++ with another QML object as parameter
You can pass QML object ids as function parameters just fine. In C++ those work as QObject *. Also, besides ids you can use the parent property, or children[indexOfChild]. Note that you don't pass the actual objects, since that would require invoking a copy constructor, and copying is disabled for all QObject derived classes, it is passed by reference, which works in JS with var and in C++ with QO

Categories : Qt

QML - Dynamically swap the visibility/opacity between overlapping Text and TextArea
You can implement placeholderText for TextArea the same way Qt does in TextField. The source can be found here: TextField.qml When you remove all the comments and properties, you basically have a background and on top of that a MouseArea, the placeholderText Text and a TextInput. Since you need to have the placeholder visually below the TextArea, you must have a transparent background: Placehold

Categories : Qt

Order of items in QMap and QMultiMap
From the Qt documentation about QMap::iterator : Unlike QHash, which stores its items in an arbitrary order, QMap stores its items ordered by key. Items that share the same key (because they were inserted using QMap::insertMulti(), or due to a unite()) will appear consecutively, from the most recently to the least recently inserted value. So it seems that QMap keeps the reversed inse

Categories : Qt

Connect QML signal of arbitrary placed .qml-file to Qt slot
The good practice is making your qml file part of the app executable by putting into .qrc resource file with Qt creator or by hand: http://qt-project.org/doc/qt-5/qtquick-deployment.html#managing-resource-files-with-the-qt-resource-system And the you can make use of it with something like: QQuickView view(QUrl("qrc:///res/qml/main.qml"));

Categories : Qt

Bogus widget in Qt Creator
It's the widget you're creating in your constructor that is "bogus". The widgets you created in the forms editor belong to the Ui::MainWindow, you must not re-create them in your main window. Remove this from your MainWindow: QPushButton *pushButton; QPlainTextEdit *plainTextEdit; Remove the widget creation from the constructor: plainTextEdit = new QPlainTextEdit(this); Change your on_pushB

Categories : Qt

ListView scrolling animation
The ViewTransition provides a lot of interesting examples on how to animate a ListView for operations like populate (the transition for the initial items at component creation), add, remove (self-explanatory) as well as other operations. Given a ListView you define an element Transition for each operation you want to animate. The animation framework can be exploited to create compound animations,

Categories : Qt

QDesktopWidget and windows taskbar
I don't know why you use QDesktopWidget for running in fullscreen mode! You can simply set your MainWindow state to fullscreen by : this->setWindowState(Qt::WindowFullScreen);

Categories : Qt

Paste at not correct position for ellipse
getEntity *Ellipse::clone() { Ellipse *e = new Ellipse; e->p1.x(); e->p1.y(); e->p2.x(); e->p2.y(); e->p3.x(); e->p3.y(); e->majRadius = majRadius; e->minRadius = minRadius; return e; }

Categories : Qt

QWidgets Leaving Artifacts Of Previous Paint
I found what appears to be a solution. The solution was to update() (as suggested by vhancho), but specifically to update the parentWidget of the object after altering its geometry. (This makes sense to me since a child's geometry is relative to the parentWidget, not the child itself. I also had another similar episode of confusion when updating the geometry topLeft, which, of course, will alway

Categories : Qt

Not able to connect a c++ signal to a slot in QML
and in my FooTabView.qml i have the below code import xxx 1.0 ..... ..... Foo.onFooAdded: { ..... } This part looks like the using of attached signal, not like object's signal. Try to setup connection via such call: fooInstance.fooAdded.connect(someJsFunction)

Categories : Qt

Linking Qt + CUDA + external library
Try these in your .pro file. I used it to link to CUDA on Linux successfully : # Define output directories CONFIG(release, debug|release): CUDA_OBJECTS_DIR = release/cuda else: CUDA_OBJECTS_DIR = debug/cuda # This makes the .cu files appear in your project OTHER_FILES += vectorAddition.cu # CUDA settings <-- may change depending on your system CUDA_SOURCES += vectorAddition.cu unix{

Categories : Qt

Resizable window after fixed size
From the Qt documentation:QLayout Class Reference sizeConstraint : SizeConstraint This property holds the resize mode of the layout The default mode is SetDefaultConstraint. Access functions: SizeConstraint sizeConstraint () const void setSizeConstraint ( SizeConstraint ) SizeConstraint is an enum with this possible values: enum QLayout:: SizeConstraint { SetDefaultConstraint , SetN

Categories : Qt

Read XML file or create new one with root element if file doesn't exist
Use something like this: QFile fileXML; bool hadToCreateXML=false; bool wasLoadedCorrectly=false; fileXML.setFileName("G:/logs.txt"); if(!fileXML.open(QIODevice::WriteOnly | QIODevice::Text)){ qDebug() << "failed creating file" << endl; } else{ hadToCreateXML=true; QDomDocument tempFirstTime; //tempFirstTime.setContent(&fileXML); don't u

Categories : Qt

QWidget get geometry when maximized
The solution comes from looking at the QWidget's state (isMaximized, isFullscreen) and then getting geometry from the QDesktopWidget QWidget *widget = ... QRect geom; if (widget->isMaximized()) { geom = QApplication::desktop()->availableGeometry() } else if (widget->isFullScreen()) { geom = QApplication::desktop()->screenGeometry() } else { geom = widget->frameGeometry(

Categories : Qt

Qt: Style the >> arrow when a QToolBar is too small
You cannot do it via CSS, however it can be done using a custom styling: Inherit a new class from QStyle / QCommonStyle. Reimplement pixelMetric to change a size of the button. Qt4: Create a slot standardIconImplementation to change an icon of the button. Qt5: Reimplement standardIcon to change an icon of the button. create this style and use setStyle to apply it to the toolbar (or to the ap

Categories : Qt

How to scroll to the specified line in QPlainTextEdit?
Use QPlaintextEdit::document to get the QTextDocument. Use QTextDocument::findBlockByLineNumber to get QTextBlock of a specific line number. Remember though, it starts from line 0, not line 1. Then create a QTextCursor using this QTextBlock and set it to your QPlainTextEdit. int ln=25; QTextCursor cursor(p_textEdit->document()->findBlockByLineNumber(ln-1)); // ln-1 because line number s

Categories : Qt

How to add files in the RPM package of an Sailfish OS project?
This isn't a RPM question per se: you seem to be asking how to configure your application through *.pro and *.yamp if you deliver content in *.rpm packages. The packaging answer is: Patch the configuration files exactly the same as if you were installing the *.wav files manually (i.e. not through *.rpm). You will need to copy the *.wav content into the %buildroot tree that is used to stage the f

Categories : Qt

QMdiArea not adding subwindow
1. Declare your QMdiSubWindow When you declare a QMdiSubWindow, give mdiArea as argument QMdiSubWindow *subWindow = new QMdiSubWindow(mdiArea); or you can use setParent ( QWidget * parent ) QMdiSubWindow *subWindow = new QMdiSubWindow(); subWindow->setParent(mdiArea); 2. Create and add your QWidget in your QMdiSubWindow QWidget *myWidget = new QWidget(); subWindow->setWidget(myWidget

Categories : Qt

Pop-up notification about wrong input in Qt
You can create a QToolTip that remains active until the time expires or you call: QToolTip::hideText() You create this QToolTip with a call to this static function: http://qt-project.org/doc/qt-5/qtooltip.html#showText-2 Passing in a -1 for the msecDlayTime will leave the QToolTip up until the user clicks the mouse. The downside is that only the latest version of Qt supports this.

Categories : Qt

How can I organize files under the qml.qrc folder in Qt Creator?
From the Qt documentation: The Qt Resource System By default, resources are accessible in the application under the same file name as they have in the source tree, with a :/ prefix, or by a URL with a qrc scheme. It is also possible to specify a path prefix for all files in the .qrc file using the qresource tag's prefix attribute: this example show how to do it: <RCC> <qres

Categories : Qt

Pyqt5 & QML2 deploy on debian/mint (dev - ubuntu)
Here is no any known reason of this behavior at this moment. I've created a bugreport and found kinda workaround-solution of the problem. The problem can be avoided by using QQmlApplicationEngine instead of QQmlEngine to create qml components. It seems QQmlEngine is buggy because these 2 classes do almost the same work. from PyQt5 import QtQml engine = QtQml.QQmlApplicationEngine() engine.load(Qt

Categories : Qt

TCP-Program gets no connection from remote pc
It's likely to be a bind issue, and/or a firewall issue. If your listener is only bound on 127.0.0.1 then connections between 2 machines won't work as the traffic isn't heard on the interface. You need to set the bind address to 0.0.0.0 (which means any) usually to achieve this. Also, check your firewall isn't blocking your traffic on these ports if they are bound to any interface. EDIT Example

Categories : Qt

Style QComboBox's sub-control down-arrow when mouse is hovering over the QComboBox via QSS
I don't know is QSS powerful enough to do this(I think no), but with eventfilter you can do this very easy: bool MainWindow::eventFilter(QObject *obj, QEvent *event) { if (obj == ui->comboBox && event->type() == QEvent::Enter) { //user enters combobox, so we apply stylesheet ui->comboBox->setStyleSheet("QComboBox::down-arrow{background-color: red}");

Categories : Qt

How select an area in QQuickPaintedItem
You need to implement selection yourself. You can create MouseArea that will track mouse activity and update selected rect accordingly. I mean something like this: DocumentViewer { // Your QQuickPaintedItem id: viewer MouseArea { anchors.fill: parent acceptedButtons: Qt.LeftButton property real originX: 0 property real originY: 0 onPressed: {

Categories : Qt

Import SQLite database using Qt/QSqlDatabase
So finally I was able to reach my goal by using the sqlite backup api (which is distributed as .h and .c with most Qt versions). On the documentation page SQLite Backup there are a few examples, where a database is copied either from a file to an in-memory db, or from an in-memory to a file. In my case I used the following function (1:1 from doc page, only several comments removed): int loadOrSav

Categories : Qt

QDateEdit return to previous state on button click in Qt C++
At any moment the state of a QDateEdit (which is actually a specialized QDateTimeEdit) can be retrieved by calling its date() method. Then, as was already said, you need to put this value into a QDate variable of your class and then create a slot which you connect to the button click and which then calls setDate to set the QDateEdit back to this date. Below is a code snippet which shows one wa

Categories : Qt

How to detect that an item in a QStandardItemModel is dropped onto another?
From studying the QStandardItemModel source code, I realized that one has to override QAbstractItemModel.dropMimeData, in order to react to item drops. QStandardItemModel moves items around in its implementation of dropMimeData, but in a way that a subclass can't hook into, so you have to handle dropMimeData yourself. This is my dropMimeData based solution, item representations are included with

Categories : Qt

compiler error C2248:'QObject::Qobject':cannot access private member declared in class 'QObject'
Make sure your Q_DECLARE_METATYPE statement is outside of your namespace and that you fully qualify your class name. See the Q_DECLARE_METATYPE doc for more detail. namespace GUI { class Connection : public QObject { ... }; } Q_DECLARE_METATYPE(GUI::Connection)

Categories : Qt

Save files into specified directory in Qt
The QFileDialog ist for a user to choose a location for saving, not the actual saving process. How you save a list of files depends on what exactly you have, if you mean a QStringList of file locations you simply want to copy the easiest way would be something like this: QStringList input_file_locations; QString output_file_location = QFileDialog::getSaveFileName(...); for (int i = 0; i < inpu

Categories : Qt


Recently Add
Making changes to a QTextEdit without adding an undo command to the undo stack
How to set the cursor for a header in a QTreeWidget in PySide?
Why does all selected QGraphicsItem not receive mouseMove event?
Connect to PostgreSQL server with "cert" authentication method using QSqlDatabase
How to implement custom boolean widget for use with QDataWidgetMapper?
How to make tab's item to be created programmatically?
Dimensioning in Qt
How to reload Page in blackberry cascades QML
Bind to imported Javascript property
Styling Treeview Qt Show Number of Elements
call QML function from C++ with another QML object as parameter
QML - Dynamically swap the visibility/opacity between overlapping Text and TextArea
Order of items in QMap and QMultiMap
Connect QML signal of arbitrary placed .qml-file to Qt slot
Bogus widget in Qt Creator
ListView scrolling animation
QDesktopWidget and windows taskbar
Paste at not correct position for ellipse
QWidgets Leaving Artifacts Of Previous Paint
Not able to connect a c++ signal to a slot in QML
Linking Qt + CUDA + external library
Resizable window after fixed size
Read XML file or create new one with root element if file doesn't exist
QWidget get geometry when maximized
Qt: Style the >> arrow when a QToolBar is too small
How to scroll to the specified line in QPlainTextEdit?
How to add files in the RPM package of an Sailfish OS project?
QMdiArea not adding subwindow
Pop-up notification about wrong input in Qt
How can I organize files under the qml.qrc folder in Qt Creator?
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.