QMessageBox::about( this, "About Application",
"<h4>Application is a one-paragraph blurb</h4>\n\n"
"Copyright 1991-2003 Such-and-such. "
"For technical support, call 1234-56789 or see\n"
"http://www.such-and-such.com" );
This code is creating the About message box which I wanted to have with two exceptions:
1) I would like to change the icon in the message box with an aaa.png file
2) And I would like to have the link clickable. It looks like hyperlink (it is blue and underlined) but mouse click does not work
Any ideas?
I think you should create a custom QWidget for your about widget. By this way, you can put on the widget all you want. By example, you can place QLabel using the openExternalLinks property for clickable link.
To display a custom image on the QWidget, this example may help.
For the icon, you need to just set the application icon. Something like this:
QApplication::setWindowIcon(QIcon(":/aaa.png")); // from a resource file
As for making the links clickable, I don't think it can be done with the QMessageBox::about API directly.
QMessageBox msgBox;
msgBox.setTextFormat(Qt::RichText); // this does the magic trick and allows you to click the link
msgBox.setText("Text<br />http://www.such-and-such.com");
msgBox.setIcon(yourIcon);
msgBox.exec();
For future reference, the docs state that the default type for textFormat is Qt::AutoText. The docs further state that Qt::AutoText is interpreted as Qt::RichText if Qt::mightBeRichText() returns true, otherwise as Qt::PlainText. Finally, mightBeRichText uses a fast and therefore simple heuristic. It mainly checks whether there is something that looks like a tag before the first line break. So, since you dont have a tag in your first line, it assumes that it is plain text. Set it to RichText explicitely with msgBox.setTextFormat(Qt::RichText); to make it act accordingly.
there's a message in the qtcenter about it:
http://www.qtcentre.org/threads/17365-Clickable-URL-in-QMessageBox
Use http://doc.qt.nokia.com/latest/qlabel.html#setOpenExternalLinks
main.cpp
QApplication app(argc, argv);
app.setWindowIcon(QIcon(":/images/your_icon.png"));
mainwindow.cpp (into your slot if you have one)
void MainWindow::on_aboutAction_triggered()
{
QMessageBox::about(0, "window title", "<a href='http://www.jeffersonpalheta.com'>jeffersonpalheta.com</a>");
}
Related
I'm trying to use QFileDialog as a widget, to use QFileDialog as a widget the final step for my is to disable the cancel button.
Have you an idea of how can i disable this button.
PS : I am using Qt 5.5.0
You should be able to access the various standard buttons via the QDialogButtonBox and, from there, do what you want with the Cancel button.
The following example code appears to works as expected...
QFileDialog fd;
/*
* Find the QDialogButtonBox.
*/
if (auto *button_box = fd.findChild<QDialogButtonBox *>()) {
/*
* Now find the `Cancel' button...
*/
if (auto *cancel_button = button_box->button(QDialogButtonBox::Cancel)) {
/*
* ...and remove it (or disable it if you prefer).
*/
button_box->removeButton(cancel_button);
}
}
fd.show();
The QFileDialog Class doesn't seem to have any option for this.
However, you could make your own file browser using QTreeModel and QTreeView (It's not too difficult).
There is a tutorial on how to do just that here.
It would take a while to type out all the code (sorry, I'm a slow typer), but this tutorial should allow you to have the flexibility you need to do what you want to do.
I understand that this answer isn't exactly what you asked, but I hope it is a good alternative.
EDIT: Accidentally pasted wrong link for QFileDialog Class
I want to use the abilities of a GtkLinkButton, but its design disturbs me. Rather than having a blue underlined text, I'd like it to look like a normal GtkButton.
What I tried is to use this code on my button:
GtkWidget *button = gtk_link_button_new_with_label ("region panel", "Input Sources");
gtk_button_set_relief (button, GTK_RELIEF_NORMAL);
gtk_button_set_use_underline (button, FALSE);
However, instead of changing the design, it simply does nothing.
If you want it to look like a GtkButton, then just replace it with that. You are not using any abilities that are special to GtkLinkButton.
You just need to make sure your click handler callback is getting fired. You are connected to "activate-link", however this signal will not exist on a standard GtkButton
Have a look here for the available signals.
https://developer.gnome.org/gtk3/stable/GtkButton.html
So I'm making a text editor using Qt and right now I have a button that opens a dialog called "Format text". I want it to work kind of like the dialog in notepad called "font" where you select a few text attributes from some drop down lists and it shows you what your text will look like. Right now I have it working where you can select the font style, font color, and font size and hit preview and it shows you in a box in the dialog what your text will look like. However, I have a button called "okay" which is supposed to change the highlighted text or the text you are about to type, but I can't figure out how to display those changes on the main window. The .ui files are private and a lot of the already made functions and pointers are the same in every ui file so if I change the ui file to pubic I have to change a whole bunch of things. Can anyway give me a simple answer? I'm trying to do this with as little confusion as possible. More coding and less confusion is better than less coding and more confusion for someone of my skill level. Sorry that this is all one giant paragraph and that I didn't provide any code, but I didn't think the code was necessary, however if you do need some of the code i'd be happy to share it.
Thank you for your help and your time. I hope you all have a nice evening.
QDialog have a signal called finished(), you can connect this signal with your slot. To accomplish your work, pass a QSettings or for simplicity QStringList to dialog settings (responsible for changing font, color ...), the QStringList will save user defined settings, after closing the dialog, iterate through QStringList member to alert Main window.
A pseudo code will look like this
Class Editor:
Editor::Editor()
{
TextSettings textSettings;
textSettings.setSettings(settings); // settings is a member
connect(textSettings, &finished(int)), this, SLOT(alertEditor(int)))
}
Editor::alertEditor(int s)
{
if(s == 0)
{
for (int i = 0; i < settings.size(); ++i)
settings.at(i).toLocal8Bit().constData(); // extract various user settings
}
}
Class TextSettings:
TextSettings::TextSettings(QStringList settings)
{
settings << ui->combobox->currentItem(); // font name as example
}
how can I make a QLabel to behave like a link? What I mean is that I'd like to be able to click on it and then this would invoke some command on it.
QLabel does this already.
Sample code:
myLabel->setText("Click Here!");
myLabel->setTextFormat(Qt::RichText);
myLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
myLabel->setOpenExternalLinks(true);
The answer from cmannnett85 is fine if you just want to open a URL when the link is clicked, and you are OK with embedding that URL in the text field of the label. If you want to do something slightly custom, do this:
QLabel * myLabel = new QLabel();
myLabel->setName("myLabel");
myLabel->setText("text");
myLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
Then you can connect the linkActivated signal of the label to a slot, and do whatever you want in that slot. (This answer assumes you have basic familiarity with Qt's signals and slots.)
The slot might look something like this:
void MainWindow::on_myLabel_linkActivated(const QString & link)
{
QDesktopServices::openUrl(QUrl("http://www.example.com/"));
}
How to set a specific style to a certain QMessageBox in Qt. Particularly, I would like to invoke a message box which is written below by setting a font size and color for the text "Well done!!!".
QMessageBox::information(this, "Done", "Well done!!!");
Using this static method you can not access QMessageBox directly, because its created and destroyed entirely inside function. But you may try to alter stylesheet property of calling object before call to this function. This means calling object should be descedant of QWidget...
something like this:
QString tmpStyleSheet=this->styleSheet();
this->setStyleSheet("style sheet for your QMessageBox");
QMessageBox::information(this, "Done", "Well done!!!");
this->setStyleSheet(tmpStyleSheet);
style of QMessageBox will inherit parent's style...
You will need to create a QMessageBox object for that particular message box and then either setStyle() or setStyleSheet(), in other words you cannot use the static helper method.
I have formated the text of the QMessageBox with HTML code. Sorry for the question. And thanks for answers.