Recently I'm writing a program using Qt(PyQt)'s QTableView.
But I find that the current cell/index (the focused one, which surrounded by a broken line) has same background colour to other selected cells.
Is there any way to make the current cell stand out? I'm using the Qt Designer to set the stylesheet, but I can't find useful style.
This is my first question here, if I made any mistake, please tell me. Thank you.
Also please excuse my poor English.
Regards,
Is there a specific reason why you are using QTableView? QTableWidget, which is the simple implemented QTableView, lets you achieve the desired effect easily.
1) Query QTableWidget for it's current item.
2) call QTablewidgetitem::setBackGround on it(maybe also foreground)
For to change the background color of any cell within a QTableView you need to return the color (e.g. as QVariant(QColor(red))) from your data() method of your model class, but only for calls with role parameter set to Qt::BackgroundColorRole.
There is another role Qt::BackgroundRole which is working for me too (in Qt4).
Related
I need to make a QLineEdit with non-editable word blocks.
For instance, imagine I drop a word (that actually represents a value) in a QLineEdit.
I would like to write normally on the QLineEdit, BUT if I try to move the cursor inside a word it would move over it, ie, place the cursor at the end/begining of the word.
Also, I would like the word to always show a certain highlight over it, with different colors (to emulate a box that would wrap it).
Any ideas on how to do this? Would a QTextArea be better for this? I was thinking of a QLineEdit because it would actually be inside a QTableWidget cell, so I think it may have more or less the same capabilities, am I wrong?
UPDATE I found these two functions that actually might be helpful for QLineEdit: cursorWordBackward() and cursorWordForward(), so this might help move over the words. Anyone has examples of this?
UPDATE 2 As QLineEdit does not support rich-text, the "highlight" feature I required can only be achieved with a QTextEdit. This has other issues: QTextEdit does not have the functions I mentioned in the first update above, and I don't know if it is possible to put a QTextEdit inside a QTableWidget cell.
QLineEdit can contain only plain text and certainly can't do this. I was thinking about QTextEdit, it can display HTML. But looking at the documentation, I realized that there is no way to insert non-editable block in QTextDocument (which is used by QTextEdit). I think there is no simple solution.
You can try to implement it manually. Catch textChanged() and cursorPositionChanged() signals of QTextEdit, analyze its content and cursor position and modify them if user moved the cursor into non-editable block or changed its content.
Maybe you could achieve this by using an inputMask...
Brief description: If I create a customized LineSeries class and add that one to my project, even if it's the same as original, I lose data tip functionality.
Elaborated description:
I'm using a LineChart component and I needed to render my lines so that they change color according to some value ranges. So I modified LineRenderer, applied it to my LineSeries and everything was working great. Unfortunately I later realized that I will need to supply ranges and colors dynamically as they're supposed to be customizable. This is where it gets tricky.
This is the code I use to set my lineRenderer:
var cf:ClassFactory = new ClassFactory(myLineRenderer);
lineSeries.setStyle("lineSegmentRenderer",cf);
I did not find a way to dynamically change data on a ClassFactory without making an instance of it. But if I make an instance of it, I can not set it as a style. If anyone knows of a way to do this, it would solve my problem straight out. All I need is to set an array property inside myLineRenderer. But it makes sense to me why this can't be done.
Can I dynamically make a new Class that is a clone of myLineRederer yet has one property changed?
Can I add an argument to myLineRenderer constructor? If so, how would that work with the code above?
Anyway, since that didn't work, I figured I needed to change the data supplied to myLineRenderer. For this I created my own LineSeries that has a settable Array property that it adds to the data passed to myLineRenderer. And it works great. With one little kink. As soon as I change my LineChart series from LineSeries to myLineSeries, I can't move the mouse cursor along the line and get info on each item in the chart. I removed all the changes I made to original LineSeries, but it makes no difference. What am I missing?
Right now I'm trapped between having customizable color ranges with no data tips and non-customizable color ranges with data tips. The former is still better, but I would really need both to work or at least know why that's impossible.
Any help would be much appreciated.
Take a look at the properties property of ClassFactory
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/core/ClassFactory.html#properties
I think that does exactly what you need it to.
I have been searching regards this question for months.
By default, the iconFunction of List and Tree return only Class as the icon, which is for embeded images or iconUtility kindly provided by this site http://blog.benstucki.net/?p=42. It works very well with pre-created images.
But what I really want is to accept a completely runtime generate sprite object, similar to what is done by Legend, with the color changes according to what the current status. I assume I could do something to make the ListBase to accept icon argument other than Class. Am I rite? or please kindly advise what I shall do.
Thank you very much!
Wildog
Instead of setting the icon for the tree item, I would create a custom item renderer using TreeItemRenderer as a starting point. Then put whatever component you want to the left of the text and move the text to the right a bit. Another advantage of this approach is that you can have your sprite change dynamically as the data that gets set to the item renderer changes. Hope that helps.
I'm not sure if this is exactly what you want to do, but you can turn your sprite into BitmapData easily enough (Which you can use to create a BitmapAsset)
e.g.
var bmp:BitmapData = new BitmapData(sprite.width, sprite.height);
bmp.draw(sprite);
var bmpasset:BitmapAsset = new BitmapAsset(bmp);
HI..
i am new to QT,i want to know how to customize the listview in QT i.e i want to add multiple icon in single row.. etc.. i tried lot i am not getting how to do that..
i tried with Qlistwidget, in tat i can only insert single row with one image.. i am not able to place multiple icon with desired locations..
please assist me, which control is good listview or listwidget.
and how to customize the same according to my view
if you have any sample examples. please provide me the link.
Thanks
You can implement a delegate to customize the rendering of the items in your view.
From the model/view programming docs: delegates are responsible for rendering individual items in the views.
See the pixelator sample for example usage.
Take a look at QTableView or QTableWidget. You can insert the icons in the first two columns and the text in the third column. Or any other way you like it.
I guess you can use some delegates.
Have a look at http://qt.nokia.com/doc/4.6/model-view-delegate.html
Hope it helps !
I've got a QTableView for which I want to display the last column always in edit mode. (It's a QComboBox where the user should be able to always change the value.)
I think I've seen the solution in the Qt documentation, but I can't find it anymore. Is there a simple way of doing it?
I think I could archive this effect by using openPersistentEditor() for every cell, but I'm looking for a better way. (Like specifying it only one time for the whole column.)
One way to get the automatic editing behaviour is to call the view's setEditTriggers() function with the QAbstractItemView::AllEditTriggers value.
To display the contents of a given column in a certain way, take a look at QAbstractItemView::setItemDelegateForColumn(). This will let you specify a custom delegate just for those items that need it. However, it won't automatically create an editor widget for each of them (there could in principle be thousands of them), but you could use the delegate to render each item in a way that makes it look like an editor widget.
There are two possibilities:
Using setIndexWidget, but Trolltech writes:
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.
(And it breaks the Model/View pattern…)
Or using a delegate's paint method. But here you have to implement everything like enabled/disabled elements yourself.
The QAbstractItemModel::flags virtual function is called to test if an item is editable (see Qt::ItemIsEditable). Take a look at Making the Model Editable in the Model/View Programming documentation.
I can't see an easy way to do this, but you might be able to manage by using a delegate. I honestly don't know exactly how it would work, but you should be able to get something working if you try hard enough. If you get a proper delegate, you should be able to set it on a whole view, one cell of a view, or just a column or row.