I've got table view that is reading from SQL Database in one of my Qt project. It contains names column, and column that store the path of some image. How i can show the image like a ToolTip, when i do hover with the mouse on some of the image paths? I 've activated the mouse tracking, but i really don't know how to use it. If you can please provide some example. Than you a lot in advance.
The view's model should respond to Qt::TooltipRole and return the tooltip's content. It can contain HTML tags, including img tag that displays an image:
class Model : public QAbstractTableModel {
public:
//...
QVariant data(const QModelIndex &index, int role) const {
if (role == Qt::ToolTipRole) {
// find path for specified index
return QString("<img src='%1'>").arg(path);
}
//...
}
If you're using a built-in model class such as QSqlRelationalTableModel, you can create a subclass of that class and reimplement data function.
Related
I have this class derived from a Layout<view> which is the WrapLayout example from Creating a Custom Layout:
Tthe code is a little big, so I put it in this pastebin:
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace CustomLayout.ViewModels
{
// ...
// [EDIT] puting the relevant code for put the images whit
/// a tap gesture in the layout
var images = GetImages();
int i = 0;
foreach (var photo in images.Photos)
{
var image = new Image
{
Source = ImageSource.FromResource(photo),
WidthRequest = 50,
HeightRequest = 75
};
var cartaoTap = new TapGestureRecognizer();
cartaoTap.Tapped += (s, e) =>
{
cartaoClick(i);
};
image.GestureRecognizers.Add(cartaoTap);
customLayout.Children.Add(image);
i++;
}
// ...
private void cartaoClick(int index){
Navigation.PushAsync(new CartaoPage(cartao.GetImagem(index), cartao.GetNome(index), cartao.GetDescricao(index)));
}
}
pastebin Raw Code for the CustomLayout class
"Cartao" is a class with attributes like Nome, Descricao and Imagem.
In the tap gesture event I pass the int "i" value to the CartaoClcik(int index) method when I added the image in the CustomLayout, in my mind, I can get the index passed to the call of this method when I added the image in the click of the mouse in one of the image showed, but, when I run and click in a image, the index parameter is alawys of the last image added
[EDIT:].
After an inhumane search job on the internet, I see that is possible to implement a class derived from Image() and then implement the GestureRecognizer command directly in this class, but I dont know how I can implement that and also I dont know how to pass the parameter needed for the page to show the image in full screen in the `CartaoPage(Image img, string nome, string descr) whose parameters have to be passed in when the user click in a image showed in they screen
someone can help me?
[SOLVED]
I solved this question, to solve I created a class derived from Image() with a public int ID {get; set;} and then fill this attribute when I instantiate my image using my own class and then I pass this ID for my index.
I know that not is a elegant solution but is working here.
thanks for all
I am facing unique issue with nspopupbutton in one of my mac application.
I am using table view to load the filters, filters having different options, We can select the option from dropdown. As like I shown below.
My Issue is , After adding another filter (table view cell), My first cell dropdown text showing reversely. Please find the screenshot below.
Please share your thoughts , I really trapped in this issue.
Issue only in High Sierra MacOS.
Edit
I am creating custom cell in XIB as like below and binding the NS elements using tag
Code I used to load table view
public override nint GetRowCount (NSTableView tableView)
{
return appliedFilters.Count;
}
public override NSView GetViewForItem (NSTableView tableView, NSTableColumn tableColumn, nint row)
{
var vw = (FiltersCell)tableView.MakeView (parentVC.appliedFilters.ElementAt((int)row), this);
// Binddata is method I used to bind data in FIlterCell
vw.BindData (parentVC.appliedFilters [(int)row].ToString(), (int)row,parentVC);
return vw;
}
public override nfloat GetRowHeight (NSTableView tableView, nint row)
{
return 30;
}
macOS HS changes a number of layer based things, and if we are using the "old" NSCells somewhere it wouldn't surprise me they broke something.
You could try setting your parent view to layer based (WantsLayer = true or in IB) and see if that "fixes" things.
Multiple people have hit layer based regressions / issues in HS (not bugs in Xamarin.Mac).
From xamarin team
In my Xamarin app, I create a button (Xamarin.Forms.Button) programmatically. I need this button to show a different background image under normal vs hovered state. I have created a style resource similar to what is described at How to indicate currently selected control in Xamarin?. However, I cannot figure out how to apply this style to the button.
The Button class exposes a property called Image that is of FileImageSource type. The closest API I found to load my style resource is ImageSource.FromResource static method. However, this method seems to return StreamImageSource instance which is not what we need.
Class Button does not seem to provide any Style property.
Can you please suggest how I can programmatically associate a style to the button? Regards.
To achieve this request you need custom renderers.
To be able to apply your style f.e.: "myButtonStyle.xml" you have to create a custom renderer for your target platform:
Android:
[assembly: ExportRenderer (typeof (YourExtendedButtonClass), typeof (MyCustomButtonRenderer))]
namespace YourApp.Droid
{
public class MyCustomButtonRenderer : ButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
var myButton = this.Control as Android.Widget.Button;
myButton?.SetBackgroundResource(Resource.Drawable.myButtonStyle);
}
}
}
I would like to implement some think like toggle button in scout eclipse.
What I need is to change image of button for state.
I see function
setIconId(String)
but I dont know how to find parameter for this function. How to find image that scout use for different state of button?
Marko
setIconId(..) and Icons
It is a good practice in your Scout Application to pass as Argument from setIconId(..) a constant defined in the Icons Class. See Icons page on the wiki.
An example for your use case:
setIconId(Icons.WeatherSun)
In the Demo Widget Application there is an Icons class:
org.eclipsescout.demo.widgets.shared.Icons
Here some constants defined in this class:
public static final String WeatherRain = "weather_rain";
public static final String WeatherSnow = "weather_snow";
public static final String WeatherSun = "weather_sun";
The values defined in the constants represent an identifier for the image.
The Image lookup is realized by the ImageLocator. (Depending on the UI technology, the appropriate IconLocator will be used. For example, in case of Swing the SwingIconLocator implementation).
In case of weather_sun the default implementation of the ImageLocator will look for a File called weather_sun.<ext> (where <ext> can be gif, png and so on) in the \resources\icons\ folder of each plugins. In this case it will find the File: \org.eclipsescout.demo.widgets.client\resources\icons\weather_sun.png
If the image is not found, you will see a log entry like this:
!MESSAGE org.eclipse.scout.rt.ui.swing.SwingIconLocator.warnImageNotFound(SwingIconLocator.java:141) could not find image 'weather_sun'
In the Scout SDK, there is an Icons Editor. This Editor represents all the constants defined in the Icons class and the corresponding Icon. Is a file not found a red square is displayed instead of the image.
Toggle Button
There is no specific field for Toggle Button, use an AbstractButton an set the display style to DISPLAY_STYLE_TOGGLE.
See also:
10.8 - Buttons and Links in the Scout Boook.
ToggleButton wiki page.
Changing the icon in a Toogle Button
I think this code snippet does what you are looking for:
#Order(10)
public class ToggleButton1 extends AbstractButton {
#Override
protected boolean getConfiguredProcessButton() {
return false;
}
#Override
protected void execClickAction() throws ProcessingException {
if (isSelected()) {
setIconId(Icons.WeatherSun);
}
else {
setIconId(Icons.WeatherRain);
}
}
}
It would also be possible (and even better) to use execToggleAction instead of execClickAction.
Screenshot:
i have a user control that descends from UserControl.
When dropped onto the form the user control is invisible, because it doesn't have any kind of border to show itself.
The PictureBox and Panel controls, at design time, draws a dashed 1px border to make it visible.
What is the proper way to do that? Is there an attribute you can use to make VS add that?
There is no property that will do this automatically. However you can archive this by overriding the OnPaint in your control and manually drawing the rectangle.
Inside the overridden event you can call base.OnPaint(e) to draw the controls content and then add use the graphics object to paint the dotted line around the edge.
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (this.DesignMode)
ControlPaint.DrawBorder( e.Graphics,this.ClientRectangle,Color.Gray,ButtonBorderStyle.Dashed);
}
As you can see you will need to wrap this extra code in an if statement that queries the controls DesignMode property so it only draws in your IDE.
The way that Panel does this (which suggests that this is the actual proper way of doing this) is with the DesignerAttribute. This attribute can be used for design time additions to Control-components as well as non-control components (like Timer).
When using the DesignerAttribute you need to specify a class derived from IDesigner. For a Control designer specifically, you should derive from ControlDesigner.
In your particular implementation of ControlDesigner you want to override the OnPaintAdornment. The purpose of this method is specifically drawing designer hints on top of the control, like a border for example.
Below is the implementation that Panel uses. You could copy that and use it for your control, but you obviously need to adjust the parts that specifically refer to the Panel class.
internal class PanelDesigner : ScrollableControlDesigner
{
protected Pen BorderPen
{
get
{
Color color = ((double)this.Control.BackColor.GetBrightness() < 0.5) ? ControlPaint.Light(this.Control.BackColor) : ControlPaint.Dark(this.Control.BackColor);
return new Pen(color)
{
DashStyle = DashStyle.Dash
};
}
}
public PanelDesigner()
{
base.AutoResizeHandles = true;
}
protected virtual void DrawBorder(Graphics graphics)
{
Panel panel = (Panel)base.Component;
if (panel == null || !panel.Visible)
{
return;
}
Pen borderPen = this.BorderPen;
Rectangle clientRectangle = this.Control.ClientRectangle;
int num = clientRectangle.Width;
clientRectangle.Width = num - 1;
num = clientRectangle.Height;
clientRectangle.Height = num - 1;
graphics.DrawRectangle(borderPen, clientRectangle);
borderPen.Dispose();
}
protected override void OnPaintAdornments(PaintEventArgs pe)
{
Panel panel = (Panel)base.Component;
if (panel.BorderStyle == BorderStyle.None)
{
this.DrawBorder(pe.Graphics);
}
base.OnPaintAdornments(pe);
}
}
ScrollableControlDesigner is a public class that you may or may not want to use as a base for your particular designer implementation.