0

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.

1 Answers1

1

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

}
SIFE
  • 5,567
  • 7
  • 32
  • 46
  • Doesn't seem too complicated thanks for the answer. If I don't get a better answer in 30 minutes I'll mark your answer. –  Sep 11 '12 at 00:33