I have managed to change the "color" property of QML text with C++ using this:
theText->setProperty("color", "red");
but if I try
theText->setProperty("font.pointSize", 20);
then nothing happens(it's not that size), I've tried this with other things that include a "." but none seem to work, I think the "." may be part of the problem. I'd really appreciate if someone could help me change the QML font size using C++.
Look for actual property name. And as far as i know there is no sub-properties in QObjects... So you need something like this:
QFont f = theText->property("font").value<QFont>();
f.setPointSize(20);
theText->setProperty("font",f);
Related
In my code I have widgets and change their styles the following way:
resultGroupBox->setStyleSheet("background-color:#7979ec;");
And later in code:
resultGroupBox->setStyleSheet("font: bold 14px\"Verdana\"");//this is done by function (set_fonts());
After the second style is applied the first is lost. I wonder if there is a way to deal with this (I need the both the fonts and the background), except for setting background-color and fonts in the same command.
It looks like your function is "setStyleSheet", isn't there a function to "AddStyle"?
Even better is adding a class instead of a style. For example with the jQuery addClass function. See https://api.jquery.com/addclass/
I am trying to get the icon of an app (doesn't matter which one). I noticed Qt doesn't have something like GDesktopAppInfo and therefore I tried getting it through QSettings from /usr/share/applications/appname.desktop. That's already a problem, because the desktop file might not be there. Anyway, going further to extract the Icon key. Now I dunno how to find the url (notice that I need the url, sure I could make a QIcon, but I need to export it to QML, which would mean another QQuickImageProvider class, anyway, I don't wanna go that way). Is it possible, or is the aforementioned QQuickImageProvider my only solution?
Here is a little guide that might help you find your way. Keep one thing in mind: start with the basic case, get code running and extend it to more difficult cases later.
For now, lets assume the following:
.desktop file is in /usr/share/applications
App icon is in SVG or PNG format
App icon path is absolute
App name is lower case and does not contain whitespace
Input: App name "git-cola"
Read /usr/share/applications/git-cola.desktop
Use a QRegularExpression to get the Icon value
You get an absolute iconPath, e.g. /usr/share/git-cola/icons/git.svg
Have an invokable C++ function that exposes a QUrl to QML
In QML, set the source property of an Image to getIconUrl("Target App")
where 4. looks something like
QUrl MyClass::getIconUrl(QString appName)
{
// get iconPath from appName
return QUrl::​fromLocalFile(iconPath);
}
If things are running, you can add support for
Multiple .desktop locations (there might be a handful or so)
Add support for relative paths
Add support for XPM files
You can use QIcon::fromTheme(QString iconName) to find the icon. It works most of the time but it's not as reliable as gtk
I'm a student programmer currently developing an application for work using Qt4. I am building an equation editor and I'm having issues attempting to highlight a string within my QTextEdit field. I have a function that parses through the QTextEdit string and returns an a start and end integer of where an error is located. My original strategy was to use HTML tags at these two points to highlight the error. Unfortunately there appears to be an issue with html tagging and the equation syntax.
What I think I need is a strategy that relies on Qt's library to set a background color between these two indices. I began looking a QSyntaxHighlighter; however I think that this is more for highlighting using a predefined set of laws and not for just grabbing up anything between a & b and setting the background color. If I can use syntax highlighter please provide me with and example or reference as I have already read through the documentation and didn't find anything.
Thanks for any help in advance!
P.S. Just to emphasize on the html compatibility issues; html becomes problematic due to multiple < and > signs used.
You can use QTextCursor and QTextCharFormat for it:
QTextEdit *edit = new QTextEdit;
...
int begin = ...
int end = ...
...
QTextCharFormat fmt;
fmt.setBackground(Qt::yellow);
QTextCursor cursor(edit->document());
cursor.setPosition(begin, QTextCursor::MoveAnchor);
cursor.setPosition(end, QTextCursor::KeepAnchor);
cursor.setCharFormat(fmt);
In my project i'm trying to use qt linguist. When i change the language from English to Turkish, it is working all constant label.
But some labels i m loading them dynamically according to scenario of use cases.
Whatever i do with qt linguist, it doest workthe texts of these label.
How can i get rid of this problem?
Any help will be apprecialted
Qt has a guide to internationalization, which includes the basic information: to wrap your string in a tr function call.
label->setText( tr( "Hello, World!" ) );
In addition to this, if you want the language to change on the fly, you'll need to identify when the context has changed, and update your labels appropriately. Unfortunately, I can't easily put my hands on the signal that indicates when to do so.
I'm trying to print the content of a QTextEdit. For that I'm using QTextDocument::print(QPrinter*). Doing that, a page number is automatically added at the right bottom of the page.
Is there any way to change its format / move it / get rid of it?
Thanks.
As far as I know that is hard coded into Qt, so you can't change it.
Have a look at QTBUG-1688. There you see that this fact has already been reported, but they don't seem to work on it. So you will have to do it yourself, I think.
If you need that, there is an way. You can use
void QTextDocument::drawContents ( QPainter * p, const QRectF & rect = QRectF() )
Add your desired footer using this.. Obviously it isn't a good one but if you need it for sure, make use of it.
I haven't give a try though. But it should work.