w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » QT » Page 1
QListWidgetItem items overlap each other
If you want to use setMinimumSize() for a QLabel, and QLabel has parent. use a QGridLayout as parent of your widget. layout apply minimum size of it's children. if you don't want to use QGridLayout, you can setMinimumSize() for parent to proper value. this value is sum of minimum size of all it's children.

Categories : Qt

Why QGraphicsItem::ItemIsMovable has no effect?
If the item is not set as selectable, it will also not be able to be moved. w->setFlag(QGraphicsItem::ItemIsSelectable, true); In addition, as you're adding a widget to the scene, the widget is embedded in a QGraphicsProxyWidget. As the documentation states: - It forwards events between the two objects and translates between QWidget's integer-based geometry and QGraphicsWidget's qreal-b

Categories : Qt

Nodal graph in Qt for Programmable Flow Charts
There is a Diagram Scene Example which uses the Graphics View framework to make flowchart diagrams. It is an application in which you can add flowchart shapes and text and connect the shapes by arrows. The shapes, arrows, and text can be given different colors, and it is possible to change the font, style, and underline of the text. You can take a look at the code and see how to create custom gra

Categories : Qt

I cannot integrate Qt and VTK
If you have installed the VTK in a folder named, say, "VTK-install", then check if you have QVTK.lib in the VTK-install/lib/vtk-5.10/ folder. (your vtk version will be different though). In the Qt Creator, you have to edit the pro file. This is what you have to add to the end of the pro file created in Qt creator. INCLUDEPATH += C:\VTK\VTK-install\include\vtk-5.10 LIBS += -LC:\VTK\VTK-install\l

Categories : Qt

QDialog: Forbidden Cursor appears when Question Mark (?) Pressed
Insert a call to QWhatsThis.leaveWhatsThisMode() in your event handler to exit "What's this?" mode as soon as it's entered. def event(self, event): if event.type() == QtCore.QEvent.EnterWhatsThisMode: QtGui.QWhatsThis.leaveWhatsThisMode() print "Here is a useful message" return True return QtGui.QDialog.event(self, event)

Categories : Qt

Qt Connection to DB2
You can use QSqlDatabase class like this: bool createConnection() { QSqlDatabase db = QSqlDatabase::addDatabase("QDB2"); db.setHostName("mozart.konkordia.edu"); db.setDatabaseName("musicdb"); db.setUserName("gbatstone"); db.setPassword("T17aV44"); if (!db.open()) { QMessageBox::critical(0, QObject::tr("Database Error"), db.lastError()

Categories : Qt

Add QListView to QComboBox for proper display of scrollbar
You need to set fixed width for the list view and update it when combo box is resized. Also you need to adjust list view's popup window width. You can do it using event filters. Here is a proof-of-concept implementation (don't write in such style in production): class Test_class : public QObject { Q_OBJECT public: Test_class() {} virtual ~Test_class() {} QComboBox* combo_box; QListVie

Categories : Qt

QDialog: how to use question mark (?) button?
It is not a button which documented by Qt. You can detect this by catching events and checking event type: http://qt-project.org/doc/qt-5/qevent.html#Type-enum There are different types as QEvent::EnterWhatsThisMode QEvent::WhatsThisClicked and so on. I achieved something similar what are you looking for using in mainwindow event filter. if(event->type() == QEvent::EnterWhatsThisMode) qD

Categories : Qt

QML Object Type is not a type error in QTCreator
You should rename your "TabView.qml" to something like "MyTabView.qml". Because of that import import "." you have conflict of TabView from "QtQuick.Controls 1.2" and local folder "."

Categories : Qt

Downloads - what to do with open network connection while asking user for filename?
After reading through a lot of comments on related mozilla bugs (69938, 7840, 55690, 129923) I came to the conclusion slowly downloading to RAM is the best thing to do. I'm doing this by setting a fixed read buffer size on the QNetworkReply, and then with a QTimer slowly reading into another in-RAM buffer. The (PyQt) implementation can be found here.

Categories : Qt

QML inheritance
Yes, absolutely. The Qt docs include an example of how to create a reusable Button component. Copying from the docs, here's their Button: //contents of Button.qml import QtQuick 1.0 Rectangle { id: button width: 145; height: 60 color: "blue" smooth: true; radius: 9 property alias text: label.text border {color: "#B9C5D0"; width: 1} gradient: Gradient {

Categories : Qt

In QDialog, resize window to contain all columns of QTableView
The difference between the linked question and your example, is that the former is resizing a widget within a layout, whereas the latter is resizing a top-level window. A top-level window is usually decorated with a frame. On your system, the width of this frame seems to be three pixels on each side, making six pixels in all. You can calculate this value programmatically with: self.frameSiz

Categories : Qt

Qt loading indicator widget
No, there is no such widget, but there is another very simple way to do this. You can play gif animation to do this. For example: QLabel *lbl = new QLabel; QMovie *movie = new QMovie("G:/loader.gif"); lbl->setMovie(movie); lbl->show(); movie->start(); You can get gif-animation from here or use another gif. I think that it is the easiest way because you can create this animation in ap

Categories : Qt

Assertion failure with remquo function
The problem you are facing is a consequence of the way remquo() calculates the remainder. If you have a look to the docs you see that: The IEEE floating-point remainder of the division operation x/y calculated by this function is exactly the value x - n*y, where the value n is the integral value nearest the exact value x/y Hence, for certain values, the quotient is rounded up to the nex

Categories : Qt

Project ERROR: Unknown module(s) in QT: multimedia
I'm not able to post a comment, so I will write it as an answer. Your problem has been solved here: https://forum.qt.io/topic/27608/unknown-module-multimedia/6 In order to handle the issue you should try installing packages that are absent: sudo apt-get install qtmultimedia5-dev libqt5multimediawidgets5 libqt5multimedia5-plugins libqt5multimedia5 and restart your Qt Creator after that. Cheers

Categories : Qt

Qmake 5.3: define global variable
There are fundamental differences between Qt 4 and Qt 5 that won't allow you to do that. The best solution in your case is using a .pri file and include() it from your subdirs' .pro files. And: in Qt 5, you should be using top_builddir=$$shadowed($$PWD) in your .qmake.conf, and not what you typed. In Qt 4, you should place a file called .qmake.cache inside your build dir, a bit complicated to d

Categories : Qt

How does the Qt Slots works. PySide
Slots are functions. The only difference between slots and functions is that with the slot keyword, the Qt metaobject compiler (MOC) will grab a function pointer of that function and use it for it's own purpose (like responding to a signal). You can totally reproduce that kind of process by grabbing a pointer of one of your function and call it when a boolean is on true. Hope that helps. PS: My

Categories : Qt

Qt cleanup on exit?
You can do it like this (had the same problem a while back and found it to work quite well): http://www.thegeekstuff.com/2012/03/catch-signals-sample-c-code/ Good sample code + all system signals: http://www.yolinux.com/TUTORIALS/C++Signals.html

Categories : Qt

error: Failed to parse qmlimportscanner output
I know this question is pretty old, however, as I just encountered the same error and finally managed to solve it: Your Project Path must not contain spaces for qml quick projects on ios. Please do not ask me how or why this is the case (as it clearly works for desktop or android deployment), but this was the issue for me. After moving the project to a different location (a folder that does not c

Categories : Qt

Pass Events Between QML Objects
I think it could be useful the section "Signal to Signal Connect" that you can find here. Basically, each signal has a connect method which can be exploited to create a signals chain. If you are interested to forword key events (as in your example) consider instead the forwardTo property: This property provides a way to forward key presses, key releases, and keyboard input coming from input m

Categories : Qt

Strange undocumented QTimer/QEventLoop behaviour after the timer is manually restarted
I tried this and every click creates another "entered" line. The main Eventloop cannot handle another event since we are stuck in a new eventloop. This is quite easy to see when implementing a second slot and also connecting this slot to the timeout signal. The maineventloop will get stuck when calling the next eventloop and not processing any more queued events. The timer itself will also n

Categories : Qt

Tcp packets using QTcpSocket
If a large amount of data is sent, the packet can arrive in separate parts. Alternatively, multiple messages can be received in one readyRead slot. It's good practice to control this by setting the first byte(s) to the number of bytes that will be sent. Then, in readyRead, you read the first bytes and append the data to a buffer until the expected amount of data has been received. In receiving d

Categories : Qt

Replace logging backend for console.debug() console.warn()
Although the globalObject is read-only in the QQmlEngine, values stored therein are not. So you can modify the console property of the globalObject. You can do that both in C++ and in QML. Here is a trivial running example in QML: import QtQuick 2.3 import QtQuick.Controls 1.2 ApplicationWindow { visible: true width: 640 height: 480 title: qsTr("Console example") Column {

Categories : Qt

QAbstractItemView::setIndexWidget as editor
Actually docs do not tell to avoid using it at all, but make decision, based on your application behavior. Here is the quote: This function should only be used to display static content within the visible area corresponding to an item of data. If you want to display custom dynamic content or implement a custom editor widget, subclass QItemDelegate instead. I've highlighted the key word

Categories : Qt

Learning Qt: Which methodology to be used for this "advanced UI"?
After so more searches, I found that I need to use the delegate methodology. In Qt5 it's QStyledItemDelegate and in Qt4 it's QItemDelegate. I could find a nice tutorial at the moment, but I started coded it.

Categories : Qt

How to disable overwrite confirmation?
Pass QFileDialog::DontConfirmOverwrite as parameter, look at the documentation for getSaveFileName function here.

Categories : Qt

make Toast in Android by QML
Maybe something like this.. This is for InfoBanner.qml import QtQuick 2.2 Loader { id: messages function displayMessage(message) { messages.source = ""; messages.source = Qt.resolvedUrl("InfoBannerComponent.qml"); messages.item.message = message; } width: parent.width anchors.bottom: parent.top z: 1 onLoaded: { messages.item.state = "

Categories : Qt

Smoothly Updating QGraphicsscene
The problem here is the management of each node as a graphics item. Adding and removing to a scene, as well as rendering each item is going to take time. With this many items, I suggest designing it differently. Consider the node graph as a single, custom graphics item which stores a group of nodes and manages them as a single unit, rather than 600+ separate items. Designed this way, you only ad

Categories : Qt

QGraphicsRectItem::rect is not updated after item is moved
It is normal for rect. Use pos() or scenePos() instead. qDebug() << rectItem->rect() << rectItem->pos() << rectItem->scenePos(); rectItem->rect() will be same until you call setRect again but scenePos() will change accordingly to your scene.

Categories : Qt

Setting height of QMenu items
Have you tried to use QSS? This works fine for me: QMenu::item { height: 42px; margin: 0px; } You can use pMenu->setStyleSheet("QMenu::item { height: 42px; margin: 0px; }");. Note: Make sure you use :: and not : to reference the item.

Categories : Qt

Qwt: curve with padding
Set special attribute: QwtPlotCurve *curve = new QwtPlotCurve; curve->setCurveAttribute(QwtPlotCurve::Fitted, true); Not fitted: Fitted:

Categories : Qt

Can QSGNode inherit QObject?
A QSGNode cannot support signals and slots natively. But if you wanted to you could do double inheritance. #include <QObject> #include <QSGNode> class Foo : public QObject, public QSGNode { Q_OBJECT // Your additional implementation here };

Categories : Qt

Force current index to be shown in QAbstractItemView even after losing focus
You can do this with this event filter: bool MainWindow::eventFilter(QObject *obj, QEvent *event) { if (obj == ui->listView && event->type() == QEvent::FocusOut) { //when view loses focus we highlight current item ui->listView->selectionModel()->select( ui->listView->currentIndex(), QItemSelectionModel::Select ); } if (obj == ui->li

Categories : Qt

Get Qt path in project file
message(Qt version: $$[QT_VERSION]) message(Qt is installed in $$[QT_INSTALL_PREFIX]) message(Qt resources can be found in the following locations:) message(Documentation: $$[QT_INSTALL_DOCS]) message(Header files: $$[QT_INSTALL_HEADERS]) message(Libraries: $$[QT_INSTALL_LIBS]) message(Binary files (executables): $$[QT_INSTALL_BINS]) message(Plugins: $$[QT_INSTALL_PLUGINS]) message(Data files: $$[

Categories : Qt

Dynamically loaded QML-file in Tab will only be executed when Tab is shown
The created Tab inherits from Loader with its active property set to false until the Tab is clicked. Just explicitly set the active property after creating it: var component = Qt.createComponent("file://tabcontent.qml')); var tab = tabView.addTab(component); tab.active = true;

Categories : Qt

How to create a new window when I click a button in QT?
The easiest way. QLabel *l = new QLabel; l->setPixmap(QPixmap::fromImage(QImage("path"))); l->setAttribute(Qt::WA_DeleteOnClose); l->show(); If you use QImage then you should first of all convert it to QPixmap. QPixmap has special static method to do this: fromImage. http://qt-project.org/doc/qt-4.8/qpixmap.html#fromImage Also I used here Qt::WA_DeleteOnClose. What is it? It is speci

Categories : Qt

Execute JS code right after QML Application start
The handler you're looking for is Component.onCompleted. Here's a simple example: import QtQuick 2.2 import QtQuick.Controls 1.1 ApplicationWindow { visible: true width: 500 height: 500 Rectangle { id: rect anchors.fill: parent // First paint a red rectangle color: "red" } Component.onCompleted: { // Make it blue when we load

Categories : Qt

Qt Scaling/zooming contents of a QFrame (widgets, etc)
Came across a solution inadvertently while solving a different problem. I used the QFrame::grab() function to get the pixmap of the frame and all of its children and repainted said pixmap elsewhere while using the .scale(int x, int y) function on the QPainter.

Categories : Qt

Add coverity scan to Qt app
I didn't read the docs carefully enough: https://scan.coverity.com/download?tab=cxx I had to configure coverity first by running: cov-configure --comptype clangcxx --compiler clang++ --template

Categories : Qt




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.