this is my syntax editor program i want to show keyword,classes,function and ...with Separate color i set the color in config file(with Qsetting)
for example this in my config file :
FunctionColor=blue
an in my cod i read the the configfile:
QString FunctionColor=settings.value("FunctionColor").toString();
how i can set the color in this instruction:
functionFormat.setForeground(Qt::FunctionColor);
compiler gives error? what i must be doing????
It would be great if you provide clear snippet codes instead of the example instructions above. However, based on my guess, if you check Qt documentation,
setForeground
is taking QBrush type of parameter. That means, to get what you want probably, you need to add some logic to convert between the string value to the QBrush value, for example:
if (FunctionColor == "blue")
{
functionFormat.setForeground(Qt::blue);
}
See if this could fix the problem.
Related
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);
I'm starting out with Qt Creator and I'm working on mapping some key value pairs (AWG wire gauge sizes as keys and the diameter as value). In using QMap to create the map, I'm getting compile errors of 'awg_map does not name a type'. Can anyone point me in the right direction here?
I've tried adding values two ways that are supposed to work, according to the instructions found at http://doc.qt.io/qt-5/qmap.html. Both ways generate the error noted above.
#include <QMap>
QMap<QString, float> awg_map;
awg_map["20"] = 0.812;
awg_map.insert("21", 0.723);
Looks like G.M. was right with this comment
Statements such as awg_map["20"] = 0.812; and awg_map.insert("21",
0.723); aren't valid at global scope and should be in a function body (for example).
I dropped it all into the MainWindow::MainWindow and it compiled fine. Thanks for that one GM!
The digital clock in KDE Plasma 5.4.0 does not allow you to specify a custom format. I'm attempted to hack the plasmoid, which is just a QML file. However, I've been unsuccessful. There is a conditional branch, which allows you select from one of the following strings.
return Qt.SystemLocaleLongDate;
return Qt.ISODate;
return Qt.SystemLocaleShortDate;
I attempted to modify it to the following, but it's not working. Presumably I just have the syntax wrong.
return QDate::currentDate().toString("dd.MM.yyyy");
How can I modify the plasmoid to show a custom date format?
EDIT
I suspect that I might be changing the wrong line. The source code for the plasmoid I'm trying to hack is here. After decompressing the file, it's specifically at applets/digital-clock/package/. (When installed, this directory is moved to /usr/share/plasma/plasmoids/org.kde.plasma.digitalclock/.) I attempted changing line 43 of contents/ui/DigitalClock.qml.
I attempted changing the line to return "foo";, but this had no effect. Again, I'm not sure if I have the syntax correct.
As stated in the comments, the line returning this value isn't a reference to the date itself, but merely specifies the format. I'm unsure of the syntax to hack the code here, but instead, you can change the code that references this property later.
--- DigitalClock.qml.orig 2015-08-22 20:45:40.000000000 +1000
+++ DigitalClock.qml 2015-09-01 09:32:35.417197582 +1000
## -515,7 +515,7 ##
if (main.showDate) {
if (main.tooSmall) {
- dateLabelLeft.text = Qt.formatDate(main.currentTime, main.dateFormat);
+ dateLabelLeft.text = Qt.formatDate(main.currentTime, "dd.MM.yyyy");
} else {
dateLabel.text = Qt.formatDate(main.currentTime, main.dateFormat);
}
I'm trying to display different language strings in my qt app by inserting each language into a QMap<QString, QString> so it can be re-used in several places and put into different combo Boxes across the application. I do this by
creating the QMap like so in the CTOR:
m_langMap.insert(QString::fromWCharArray(L"English"), "english");
m_langMap.insert(QString::fromWCharArray(L"Dansk"), "dansk");
m_langMap.insert(QString::fromWCharArray(L"Nederlands"), "dutch");
m_langMap.insert(QString::fromWCharArray(L"Čeština"), "czeck");
m_langMap.insert(QString::fromWCharArray(L"Slovenský"), "slovak");
m_langMap.insert(QString::fromWCharArray(L"Magyar"), "hungarian");
m_langMap.insert(QString::fromWCharArray(L"Român"), "romanian");
m_langMap.insert(QString::fromWCharArray(L"Latviešu"), "latvian");
m_langMap.insert(QString::fromWCharArray(L"Lietuvių"), "lithuanian");
m_langMap.insert(QString::fromWCharArray(L"Polski"), "polish");
m_langMap.insert(QString::fromWCharArray(L"Português"), "portuguese");
m_langMap.insert(QString::fromWCharArray(L"Español"), "spanish");
m_langMap.insert(QString::fromWCharArray(L"Français"), "french");
m_langMap.insert(QString::fromWCharArray(L"Italiano"), "italian");
m_langMap.insert(QString::fromWCharArray(L"Svenska"), "swedish");
m_langMap.insert(QString::fromWCharArray(L"Русский"), "russian");
m_langMap.insert(QString::fromWCharArray(L"Українська"), "ukranian");
m_langMap.insert(QString::fromWCharArray(L"Русский"), "russian");
m_langMap.insert(QString::fromWCharArray(L"中文"), "chinese");
m_langMap.insert(QString::fromWCharArray(L"日本語"), "japanese");
I then insert them into the combo box:
QMap<QString, QString>::const_iterator it = m_langMap.begin();
while (it != m_langMap.end())
{
ui->comboBox->addItem(it.key());
++it;
}
When the app runs, I see the following:
However, if I create a separate .ui file and insert the map the same way, I see the following (even if I include this separate Dialog class into the same application), so clearly there is no font issue as far as the App not knowing how to render the different character sets....yet I cant figure out why the first one won't render the character sets?
Can someone tell me why the first doesn't work but the second does? I checked the Designer and its Locale is set to 'C, Default' in both ui files I've shown below. I can't seem to figure out what else is causing the difference for the first not to work, and the second does work within the same application.
Thanks for any help!
The other test Dialog:
Your code is correct, but the problem is that your source file cannot contain Unicode characters - apparently it is using different coding.
Save file as UTF-8 and everything should work!
In the first screenshot the font used by the combobox is much larger than in the second screenshot. My guess is that you have changed the font either in the GUI designer or in the code and the second (working) screenshot is using the default font. It might be that when you have changed the font size, you have also changed the font to something that doesn't contain all the required Unicode characters. Try changing the font used by the combobox to something else.
I have a flex 4.5 application. I want to add new line in an mx:TextArea when certain event occurs. I have been searching for the proper way to add a OS independent line ending. I found out that the File class has lineEnding property. However the documentation states that this class is not exposed when running inside a browser (which is my case).
I have searched, but I couldn't find any other class, which can provide this information. Actually I am not sure if the TextArea line ending is OS dependent or not.
So actually I have two questions: Are TextArea line endings OS dependent or not? And if so, how can I get the proper line ending in flex?
You can use String.fromCharCode(13). This will return a line ending.
This is the equivalent of PHP's chr() method.
Example:
var address_str:String = "dog" + String.fromCharCode(64) + "house.net";
trace(address_str); // output: dog#house.net
From my experience, "\r" works in both Windows and Mac.
Quite simply, you just need to add the newline character to the text of the textArea.
myTextArea.text+="\n"; //This should work, if not try the other two
myTextArea.text+="\r";
myTextArea.text+="\r\n";