I can able to build the source code using make command. but I am facing some problems while building the source code in qt creator.
Qt creator is showing only the submodule .pro files, but not showing their header and source files.
This is a question about the C++ source code/behaviour. I do not presently have a case which goes wrong, but I am concerned there may be such a case. I am not able to check every call in every combination, hence the question about the source code.
However, since you are kind enough to respond, here is outline Python code for the situation:
from PyQt5 import QtCore, QtWidgets, QtGui
def data(self, index: QtCore.QModelIndex, role: QtCore.Qt.ItemDataRole = QtCore.Qt.DisplayRole) -> typing.Any:
return super().data(index, role)
def setData(self, index: QtCore.QModelIndex, value: typing.Any, role: QtCore.Qt.ItemDataRole = QtCore.Qt.EditRole) -> bool:
return super().setData(index, value, role)
self.setGeometry(100, 100, 500, 500)
self.centralWidget = QtWidgets.QWidget(self)
self.centralLayout = QtWidgets.QHBoxLayout(self.centralWidget)
# create a QTableView
self.table = QtWidgets.QTableView()
# create a QSqlModel, and set it as view's model
self.model = MySqlQueryModel()
# set up a (MySQL) database connection
# `my_table` has `col1` which is/can be NULL and `col2` which is/can be non-NULL
self.model.setQuery("SELECT col1, col2 FROM my_table WHERE col1 IS NULL AND col2 IS NOT NULL")
# or perhaps just the following:
# self.model.setQuery("SELECT NULL AS col1, 'something-non-NULL' AS col2")
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
main = Main()
Note the following:
Here I am overriding QSqlQueryModel. If it makes a difference, I am doing exactly the same for QSqlTableModel & QSqlRelationalTableModel.
The overridden data() & setData() methods are straight pass-throughs to the base C++ methods, but via Python/PyQt. If my code were C++ instead of Python/PyQt there would be no issue.
My question is about the behaviour of the C++ QVariant returned by, say, QSqlQueryModel::data() and the C++ QVariant passed from the caller into QSqlQueryModel::setData().
My question is for all possible in-built roles (enum Qt::ItemDataRole) which might be passed to these methods, from Qt::DisplayRole through Qt::InitialSortOrderRole, inclusive, i.e. all the Qt defined Qt::ItemDataRoles, and not any kind of Qt::UserRole I might define. Thus it includes both true "data" roles (e.g. Qt::DisplayRole) and purely "appearance" roles (e.g. Qt::TextAlignmentRole).
My question concerns 2 "slightly odd" QVariant types/values:
The "invalid" QVariant. This is where QVariant::isValid() == false. I believe it can be created via plain QVariant().
The "null" QVariant. This is where QVariant::isNull() == true. I am unsure how it is created in C++.
Now, unlike C++, PyQt "maps/unmaps" these two to/from the same Python None type/value. The QVariant type is simply hidden from me. The author of PyQt states that this relies on "[a particular call] not needing to treat these two as distinguishable", which he believes "is 'mostly' the case". But he states he does not claim to know exactly what individual C++ methods might do in the way of distinguishing them.
So, my questions are:
In the case of the return value from any of the data() overrides, for any given ItemDataRole passed in are there any cases where it might return both an "invalid" and a "null" QVariant under certain circumstances, to mean different things? We are only interested in one, single role being able to return either/both of these, not in different roles where some return one and some return the other. This is because PyQt returns None to me for either/both cases, so I cannot distinguish.
In the case of the value passed into any of the setData() overrides, for any possible ItemDataRole passed in are there any cases where it would behave differently depending on whether an "invalid" or a "null" QVariant is passed in? This might mean they treat those differently such that it matters, or it might mean that they only accept one of two and error on the other. This is because I can only pass None from PyQt for either/both cases [it maps that to one of "invalid"/"null" QVariant (always the same), and I don't even know which of the two], so I cannot distinguish.
I trust that the above is a very clear statement of the issue I face when writing my code. I cannot try out every combination of roles & values for each method in every circumstance, so I am asking someone with knowledge of the code/C++ behaviour to help.
Oh, I think I get it a little better now. So, the class derived from the table model holds the data. The table object receives the data updates from the worker and stores them, then emits the dataChanged() signal. And the data() function then conveys the current data to the UI. That about right?
Yep, quite correct.
So, am I responsible for maintaining a row index for my records? (Since data uses an int to identify a row.)
I could store my table data in a hash, with an int as the key, and a structure containing the strings as the value.
You could, but if your keys are sequential and uninterrupted a hash isn't exactly efficient, maybe a vector.
In your case, where it's ListView that creates instances (objects) from your component, you can do something like:
editfield.currentItem.text = "blah blah"
But you need to add "text" property to your component. Probably this would work:
property alias text: edit_std_id.text
Or the property needs to be in Component, not item, I'm not sure.
Notice, however, that ListView can create and destroy your delegate objects at any time. It is much better to populate your delagate data from model. And if you need to modify that data (like text in your example), you should modify the model - ListView will automatically update. More info on models and views in QML: https://doc.qt.io/qt-5/qtquick-modelviewsdata-modelview.html
If that bothers you, just copy the valueAxisX, and rename the copy ValueAxisY, and uncomment the axisY line for the LineSeries.
Personally? I couldn't actually care any less.
We're just all working with what you give us so it's actually if you care to give us enough information to actually help you. Providing actual code or at least as close as possible is always going to help.
With half cut, incomplete fragments ... we'll just all guess, you'll have as much luck tossing darts blindfolded.
This is from the LineSeries and ChartView documentation pages and best I can tell what you want. It's pure QML. Using Windows/Qt5.10.0/MinGW5.3.0 I can verify this runs for me, so actual code.
@_hunter This thread is 3 years old. You would have been better off starting a new one.
That being said, the normal way for getting root to a gui application in linux is sudo -E ./yourapp. Or using something like kdesudo or gksu, etc. Very very few applications try to escalate their permissions dynamically. Linux users are used to having to launch apps like gparted with kdesu or sudo -E.
If your app requires root all the time and you don't want to have to launch with sudo or something, then install it with the sticky bit set to run as root and set it's user to root. Note: this is typically frowned on because of the security holes it opens if your app has any security issues like buffer overflows that can be used to gain a root shell.
Oh and the actual thing you were looking for is pkexec. That is how gparted launches as a different user graphically. It just uses pkexec to restart itself as root.
@Mr-Gisa Ok played with it a little bit ... linux doesn't show the clicks like windows apparently does. I don't have easy access to my Windows vm with qt in it to test right now.
There is no easy way to disable the click behavior. Here are some ideas:
You can write a custom class derived from QAction, then ignore clicks. That would be a pain though.
You could write a custom QLineEdit that draws the image (should be fairly easy, but still some work).
You could use a style sheet on the QLineEdit that loads the image and puts it as a left aligned non-repeating background image. No guarantees this would work, but it should.
You could switch your gui to QML where stuff like this is super easy. This isn't a serious recommendation, but if you find you want custom GUIs a lot then QML is definitely the better choice for designing them. Or you end up writing a lot of custom widgets.
You could just ignore the click behavior windows does
Or you could assign the click to do something like focus and select all in the line edit. That would feel natural and explain the "click".
@Chris-Bare You could do a check when your undo menu action is triggered to see if the focus is on the QLineEdit, and if so you could then call yourLineEdit->undo() directly. This would bypass your stack and act appropriately on the line edit. Same with redo but call redo().
That's a bit complicated, because the project is almost complete and I have used the QtCharts and QtDataVisualization frameworks for that. Is there a way to do it with the capabilities of the Qt framework without using Qwt? Thanks.
On Linux, you can run your app inside xvfb, and it'll strictly render offscreen in a virtual framebuffer. (Probably won't work if you are doing interesting OpenGL stuff, but normal widgets doing software rendering works fine.) You can even automate the generation of a screenshot at a certain point in the tests.
It's fairly easy to set up on a CI server with no GPU or actual display. The software thinking it's being displayed on a normal screen. You can set up multiple xvfb instances in parallel to act is different X displays, so you can have multiple "full screen" apps running at once, because they are all independent.