How can I make Tcl/Tk buttons behave like radiobuttons? - button

According to the ActiveTcl 8.5 Documentation:
ttk::radiobutton widgets are used in groups to show or change a set of mutually-exclusive options. Radiobuttons are linked to a Tcl variable, and have an associated value; when a radiobutton is clicked, it sets the variable to its associated value.
And a more general definition:
You use radio buttons for mutually exclusive settings. Clicking on one causes any other that has been pressed to pop up, just like on an old car radio.
I really prefer to use the look and feel of buttons instead of radio buttons. How can I achieve the same behaviour of radiobuttons in a group of buttons?
I found on http://wiki.tcl.tk/17899 about toggle buttons, but these behaves more like checkbuttons.
Any insights really appreacited. Thank you

You can set the button's relief to maintain it's sunken-ness.
set colours {red blue green}
foreach c $colours {
pack [button .$c -text $c -command [list pushed $c]]
}
proc pushed colour {
puts $colour
set label [.$colour cget -text]
foreach c $::colours {
.$c configure -relief [expr {$c eq $label ? "sunken" : "raised"}]
}
}

Set the radiobuttons' -indicatoron attribute to false.

Related

Pivottable.js filter dialog box button size

In my pivottable, when I clicked a field to open the filter box, its "Apply" & "Cancel" buttons are too small.
Using this style also can't make them bigger:
.pvtFilterBox{
font-size: 16px;
}
Please advise.
Found that it is nothing to do with styling.
This is because I defined the locales for 'totals' only. It won't use default locales for other words (Apply, Cancel, etc).
$.pivotUtilities.locales.en = {
localeStrings: {
totals: "TOTALS"
}
};

how to change color of background, row , row selection and header in angular 4 with bootstrap 4 data-table

I have implemented bootstrap 4 data table 4 in angular 4 but not able to change or modify row color. row selection color and header color as well.
I am using the data table 4 example : https://github.com/afermon/angular-4-data-table-bootstrap-4
and in this examples demo go through the demo 1 of link: https://afermon.github.io/angular-4-data-table-bootstrap-4-demo/
Considering the below code snippet present in data-table-component-demo1.ts got by the Git project you downloaded:
<data-table id="persons-grid"
[header] = "false"
[multiSelect] = "false"
[substituteRows]="false"
[indexColumn]="false"
[items]="items"
[itemCount]="itemCount"
(reload)="reloadItems($event)"
[pagination]="false"
(rowClick)="rowClick($event)"
[rowColors] = "callBackForChangineRowColors"
>
<data-table-column
[property]="'name'"
[header]="'Name'"
[sortable]="true"
[styleClass]="someExplicitClass"
In this, we can assign the value 'someExplicitClass' to [styleClass] as shown above and define the class someExplicitClass in our data-table-component-demo1.css file as below:
:host /deep/ .someExplicitClass{
background-color:red;
}
However, this is applied to the whole of the DataColumn and not controllable on a granular level.
We can indirectly apply only background-color using the rowEvent variable available within the rowClick(rowEvent) function of 'data-table-component-demo1.ts'
On click of the row, I will set the selected property of the row to true and thereby will trigger the onRowSelectChanged function of table.component.ts file
Now, once I set [rowColors] value to "callBackForChangineRowColors" as shown above and make the below changes in my data-table-component-demo1.component.ts file:
rowClick(rowEvent) {
console.log('Clicked: ' + rowEvent.row.item.name);
rowEvent.row.selected = true;
}
callBackForChangineRowColors(a,b,c)
{
if(b.selected)
return 'blue';
}
This way, I will be able to apply the color of blue explicitly for the selected Row.
*I could'nt unfortunately find any solution to apply any other styles on a granular level using a readily available input parameter like [styleClass] for it wasnt exposed as an #Input within our column.component.ts. If anyone has an idea, please do help me know it.

How to change (remove) selection/active color of QListWidget

In my QListWidget, there are some items that have non-default background color, I set them like so inside the custom QListWidget class:
item->setBackgroundColor(qcolor); // item is of type QListWidgetItem*
Those non-default colors that I set are distorted by the QListWidget's selection color. See an example:
Items three and four are supposed to be the same color, but they are not since the item four is selected, and thus the result color is a summation of original color and QListWidget's selection (active item?) color.
My question is how to edit or remove that selection color?
I tried inside my QListWidget (in special slot when I want to change the item's background color):
QPalette pal = this->palette();
pal.setColor(QPalette::Highlight, QColor(255,255,255,0));
this->setPalette(pal); // updated
But it did not produce any effect. what am I doing wrong? Is it a correct variable to set? Do I set it up inside QListWidget or inside its delegate?
Update: I tried using stylesheets as pointed by comment/answer, however, it will not be possible to use them for my application, because the items in my rows have 3 states (so I would need to use three colors). E.g., 3 states that correspond to three colors: pink for active, green for inactive and gray for the rest. When using stylesheets, I cannot set the custom property (let's say QListWidget::item[Inactive="true"]) to a single QListWidgetItem, but for the full QListWidget, and therefore it colors all the rows the same color.
Stylesheets were tried for similar problem here, and didn't work, therefore I make conclusion using stylesheets is not the way to go.
The background change method that I used originally works fine for my purpose, but I cannot figure out how to get rid of the default selection color (transparent light blue) which adds to the background color and produces the mixed color.
I think you'd be better served using the style sheets to do this. Here's an example
QListWidget::item
{
background: rgb(255,255,255);
}
QListWidget::item:selected
{
background: rgb(128,128,255);
}
::item indicates the individual items within the QListWidget, while :selected indicates the QListWidgetItems which are currently selected.
To then get the custom background on specific widgets, you could use custom style sheet properties. In your code, call something like this on the widget you want to apply a custom style on:
myList->setProperty( "Custom", "true" );
// Updates the style.
style->unpolish( myList );
style->polish( myList );
Then in your style sheet, define the style for your custom property like so.
QListWidget::item[Custom="true"]
{
background: rgb(128,255,128);
}
I found a suitable solution by using a delegate. So, there is no need to use QPalette; and for my problem the stylesheets will not work. This solution will also work when different rows (QListWidget or QTreeWidget) are needed to be colored in different colors, depending on some state.
The background color is set as described on the question:
item->setBackgroundColor(qcolor); // change color slot inside QListWidget class
In order to define rules how the widget is painted, I re-define the delegate:
class Delegate : public QStyledItemDelegate {};
Then I re-define Delegate's method paint(). There I define how to draw each row of my widget. More specifically, I only call custom drawing when the mouse hovering over an item, or that item is in selected state (those are the conditions when the row is selected by the light blue color which I want to avoid). The code looks like this:
void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if((option.state & QStyle::State_Selected) || (option.state & QStyle::State_MouseOver))
{
// get the color to paint with
QVariant var = index.model()->data(index, Qt::BackgroundRole);
// draw the row and its content
painter->fillRect(option.rect, var.value<QColor>());
painter->drawText(option.rect, index.model()->data(index, Qt::DisplayRole).toString());
}
else
QStyledItemDelegate::paint(painter, option, index);
// ...
}
Of course, do not forget to associate the QListWidget with Delegate:
listWidget->setItemDelegate(new Delegate());

Format datagrid column color

I have a advanced datagrid label function like this:
private function dgFormat(item:Object, column:AdvancedDataGridColumn):String{
var v3:int = item.value1 - item.value2;
return "Total: " + v3;
}
How can I change the text color of v3 dynamically? I want it to be red if it's less than zero & black otherwise.
thanks!
There's a few ways of doing this, but personally if I were you, I'd just create a custom item renderer for the columns that you want the color to change and do something like:
<s:Label text="Total: {data}" color="{data < 0?0xFF0000:0x000000}" />
This way, you bind the difference right off the bat without having to add 'total' in your data, and bind the color change as well.
You'll need a custom item renderer for your AdvancedDataGridColumn. The item renderer will check the value being set, and update the color of the text depending on its content.
This should get you started.

In a QTableWidget, changing the text color of the selected row

I'm using a QTableWidget to display several rows. Some of these rows should reflect an error and their text color is changed :
Rows reflecting that there is no error are displayed with a default color (black text on white background on my computer).
Rows reflecting that there is an error are displayed with a red text color (which is red text on white background on my computer).
This is all fine as long as there is no selection. As soon as a row is selected, no matter of the unselected text color, the text color becomes always white (on my computer) over a blue background.
This is something I would like to change to get the following :
When a row is selected, if the row is reflecting there is no error, I would like it to be displayed with white text on blue background (default behavior).
If the row is reflecting an error and is selected, I would like it to be displayed with red text on blue background.
So far I have only been able to change the selection color for the whole QTableWidget, which is not what I want !
Answering myself, here is what I ended up doing : a delegate.
This delegate will check the foreground color role of the item. If this foreground color is not the default WindowText color of the palette, that means a specific color is set and this specific color is used for the highlighted text color.
I'm not sure if this is very robust, but at least it is working fine on Windows.
class MyItemDelegate: public QItemDelegate
{
public:
MyItemDelegate(QObject* pParent = 0) : QItemDelegate(pParent)
{
}
void paint(QPainter* pPainter, const QStyleOptionViewItem& rOption, const QModelIndex& rIndex) const
{
QStyleOptionViewItem ViewOption(rOption);
QColor ItemForegroundColor = rIndex.data(Qt::ForegroundRole).value<QColor>();
if (ItemForegroundColor.isValid())
{
if (ItemForegroundColor != rOption.palette.color(QPalette::WindowText))
{
ViewOption.palette.setColor(QPalette::HighlightedText, ItemForegroundColor);
}
}
QItemDelegate::paint(pPainter, ViewOption, rIndex);
}
};
Here is how to use it :
QTableWidget* pTable = new QTableWidget(...);
pTable->setItemDelegate(new MyItemDelegate(this));
What you'll want to do is connect the selectionChanged() signal emitted by the QTableWidget's QItemSelectionModel to a slot, say OnTableSelectionChanged(). In your slot, you could then use QStyleSheets to set the selection colours as follows:
if (noError)
{
pTable->setStyleSheet("QTableView {selection-background-color: #000000; selection-color: #FFFFFF;}");
}
else
{
pTable->setStyleSheet("QTableView {selection-background-color: #FF0000; selection-color: #0000FF;}");
}
It looks ok, but you might want to look at the documentation of QStyleOption it can tell you wether the item drawn is selected or not, you don't have to look at the draw color to do that. I would probably give the model class a user role that returns whether the data is valid or not and then make the color decision based on that. I.e. rIndex.data(ValidRole) would return wether the data at this index is valid or not.
I don't know if you tried overriding data for the BackgroundRole and returning a custom color, Qt might do the right thing if you change the color there
You could, of course, inherit from the table widget and override the paint event, but I don't think that is what you want to do.
Instead, should use the QAbstractItemDelegate functionality. You could either create one to always be used for error rows, and set the error rows to use that delegate, or make a general one that knows how to draw both types of rows. The second method is what I would recommend. Then, your delegate draws the rows appropriately, even for the selected row.
You could use e.g. a proxy model for this where you return a different color if you have an error for the specific modelindex;
QVariant MySortFilterProxyModel::data(const QModelIndex & index, int role = Qt::DisplayRole) {
// assuming error state and modelindex row match
if (role==Qt::BackgroundRole)
return Qt::red;
}

Resources