crossplatform.ru

Здравствуйте, гость ( Вход | Регистрация )


  Ответ в Выравнивание текста
Введите ваше имя
Подтвердите код

Введите в поле код из 6 символов, отображенных в виде изображения. Если вы не можете прочитать код с изображения, нажмите на изображение для генерации нового кода.
 

Опции сообщения
 Включить смайлы?
Иконки сообщения
(Опционально)
                                
                                
  [ Без иконки ]
 


Последние 10 сообщений [ в обратном порядке ]
bugsstring Дата 7.10.2008, 15:44
  народ сорри Я ДЯТЕЛ ))))
Цитата
textLeft = new QAction(QIcon(":images/format_justify_left.png"),tr("Align Left"),this);
connect(textLeft, SIGNAL(triggered()), this, SLOT(setAlignLeft()));

textCenter = new QAction(QIcon(":images/format_justify_center.png"),tr("Align Center"),this);
connect(textLeft, SIGNAL(triggered()), this, SLOT(setAlignCenter()));

textRight = new QAction(QIcon(":images/format_justify_right.png"),tr("Align Right"),this);
connect(textLeft, SIGNAL(triggered()), this, SLOT(setAlignRight()));
bugsstring Дата 7.10.2008, 13:58
 
Цитата(ViGOur @ 7.10.2008, 13:11) *
Выложи исходник, если большой набросай пример воспроизводящий проблему и выложи...
А то маловато информации.

класс
#ifndef TEDIT_H
#define TEDIT_H

#include <QWidget>

class QToolBar;
class QAction;
class QTextEdit;

class TEdit : public QWidget
{

    Q_OBJECT
    public:
        TEdit();
        virtual ~TEdit();

    private slots:
        void makeBold();
        void makeItalic();
        void makeUnderline();
        void setAlignLeft();
        void setAlignCenter();
        void setAlignRight();

    private:
        QToolBar *toolBar;

        QAction *textBold;
        QAction *textItalic;
        QAction *textUnderline;
        QAction *textLeft;
        QAction *textCenter;
        QAction *textRight;

        QTextEdit *te;
};

#endif /* TEDIT_H */

имплементация
#include <QtGui>
#include "tedit.h"

TEdit::TEdit()
{
          resize(800,600);
          te = new QTextEdit;
          toolBar = new QToolBar(this);

          textBold = new QAction(QIcon(":images/format_text_bold.png"),tr("B"),this);
          connect(textBold, SIGNAL(triggered()), this, SLOT(makeBold()));

          textItalic = new QAction(QIcon(":images/format_text_italic.png"),tr("I"),this);
          connect(textItalic, SIGNAL(triggered()), this, SLOT(makeItalic()));

          textUnderline = new QAction(QIcon(":images/format_text_underline.png"),tr("U"),this);
          connect(textUnderline, SIGNAL(triggered()), this, SLOT(makeUnderline()));

          textLeft = new QAction(QIcon(":images/format_justify_left.png"),tr("Align Left"),this);
          connect(textLeft, SIGNAL(triggered()), this, SLOT(setAlignLeft()));

          textCenter = new QAction(QIcon(":images/format_justify_center.png"),tr("Align Center"),this);
          connect(textLeft, SIGNAL(triggered()), this, SLOT(setAlignCenter()));

          textRight = new QAction(QIcon(":images/format_justify_right.png"),tr("Align Right"),this);
          connect(textLeft, SIGNAL(triggered()), this, SLOT(setAlignRight()));

          toolBar->addAction(textBold);
          toolBar->addAction(textItalic);
          toolBar->addAction(textUnderline);
          toolBar->addSeparator();
          toolBar->addAction(textLeft);
          toolBar->addAction(textCenter);
          toolBar->addAction(textRight);

          QVBoxLayout *ml = new QVBoxLayout;
          ml->setMargin(1);
          ml->setSpacing(0);
          ml->addWidget(toolBar);
          ml->addWidget(te);
          setLayout(ml);
}
void TEdit::makeBold()
{
          QTextCursor cursor = te->textCursor();
          QTextCharFormat boldFormat;
          if(cursor.charFormat().fontWeight()==QFont::Normal)
          {
              boldFormat.setFontWeight(QFont::Bold);
          }
          else
          {
              boldFormat.setFontWeight(QFont::Normal);
          }
      
          cursor.mergeCharFormat(boldFormat);
}

void TEdit::makeItalic()
{
          QTextCursor cursor = te->textCursor();
          QTextCharFormat italicFormat;
          if(cursor.charFormat().fontItalic()==false)
          {
              italicFormat.setFontItalic(true);
          }
          else
          {
              italicFormat.setFontItalic(false);
          }
          cursor.mergeCharFormat(italicFormat);
}

void TEdit::makeUnderline()
{
          QTextCursor cursor = te->textCursor();
          QTextCharFormat underlineFormat;
          if(cursor.charFormat().fontUnderline()==false)
          {
              underlineFormat.setFontUnderline(true);
          }
          else
          {
              underlineFormat.setFontUnderline(false);
          }
          cursor.mergeCharFormat(underlineFormat);
}

void TEdit::setAlignLeft()
{
          te->setAlignment(Qt::AlignLeft);
/*or
          QTextCursor cursor = te->textCursor();
          QTextBlockFormat blockFmt;
          if(!cursor.hasSelection())
          {
              cursor.select(QTextCursor::BlockUnderCursor);
          }
          blockFmt.setAlignment(Qt::AlignLeft);
          cursor.mergeBlockFormat(blockFmt);
*/
}

void TEdit::setAlignRight()
{
          te->setAlignment(Qt::AlignRight);
/*or
          QTextCursor cursor = te->textCursor();
          QTextBlockFormat blockFmt;
          if(!cursor.hasSelection())
          {
              cursor.select(QTextCursor::BlockUnderCursor);
          }
          blockFmt.setAlignment(Qt::AlignRight);
          cursor.mergeBlockFormat(blockFmt);
*/
}

void TEdit::setAlignCenter()
{
          te->setAlignment(Qt::AlignCenter);
/*or
          QTextCursor cursor = te->textCursor();
          QTextBlockFormat blockFmt;
          if(!cursor.hasSelection())
          {
              cursor.select(QTextCursor::BlockUnderCursor);
          }
          blockFmt.setAlignment(Qt::AlignCenter);
          cursor.mergeBlockFormat(blockFmt);
*/
}

TEdit::~TEdit(){}



IDE - eclipse
ViGOur Дата 7.10.2008, 13:11
  Выложи исходник, если большой набросай пример воспроизводящий проблему и выложи...
А то маловато информации.
bugsstring Дата 7.10.2008, 12:55
 
Цитата(ViGOur @ 7.10.2008, 9:49) *
Посмотри в дебаге, ты попадаешь в слоты?

вроде все ок, приконекчено куда надо
дебаггер молчит

что интересно
void TEdit::setAlignLeft()
{
    QTextCursor cursor = te->textCursor();
    QTextBlockFormat blockFmt;
    if(!cursor.hasSelection())
    {
        cursor.select(QTextCursor::BlockUnderCursor);
    }
    blockFmt.setAlignment(Qt::AlignLeft);
    cursor.mergeBlockFormat(blockFmt);
}

тоже не работает... ((

точнее опять же выравнивает вправо и все

P.S.
версия Win Qt 4.4.3
версия Linux Qt 4.4.1
ViGOur Дата 7.10.2008, 9:49
  Посмотри в дебаге, ты попадаешь в слоты?
bugsstring Дата 7.10.2008, 9:47
  Сорри, народ...
нифига не работает, по кнопке выравнивает вправо и все
подскажите где я туплю

class TEdit : public QWidget
{
...
    private slots:
        void makeBold();
        void makeItalic();
        void makeUnderline();
        void setAlignLeft();
        void setAlignCenter();
        void setAlignRight();
    private:

        QToolBar *toolBar;

        QAction *textBold;
        QAction *textItalic;
        QAction *textUnderline;
        QAction *textLeft;
        QAction *textCenter;
        QAction *textRight;

        QTextEdit *te;
};

Имплементация
TEdit::TEdit()
{
       te = new QTextEdit;
   ...
    textLeft = new QAction(QIcon(":images/format_justify_left.png"),tr("Align Left"),this);
    connect(textLeft, SIGNAL(triggered()), this, SLOT(setAlignLeft()));
    textCenter = new QAction(QIcon(":images/format_justify_center.png"),tr("Align Center"),this);
    connect(textLeft, SIGNAL(triggered()), this, SLOT(setAlignCenter()));
    textRight = new QAction(QIcon(":images/format_justify_right.png"),tr("Align Right"),this);
    connect(textLeft, SIGNAL(triggered()), this, SLOT(setAlignRight()));
   ...
}
...
void TEdit::setAlignLeft()
{
    te->setAlignment(Qt::AlignLeft);
}
void TEdit::setAlignRight()
{
    te->setAlignment(Qt::AlignRight);
}
void TEdit::setAlignCenter()
{
    te->setAlignment(Qt::AlignCenter);
}


спасибо )))
но кнопку "Отправить" я жал 1 раз
это называется "Не используй предварительный просмотр НИКОГДА" )))
Alexey Дата 22.3.2008, 20:08
  О, теперь и у меня выравнивает.Спасибо за помощ.
Litkevich Yuriy Дата 22.3.2008, 14:11
  я сделал в этом файле так:
void MdiChild::ALeft()
{
setAlignment(Qt::AlignLeft);//document()->
}

void MdiChild::ARight()
{
  setAlignment(Qt::AlignRight);//document()->
}

void MdiChild::ACenter()
{
  setAlignment(Qt::AlignCenter);//document()->
}

и вроде получилось то что ты хотел, ну выравнивание покрайней мере работает
---
хотя нет, правое выравнивание не происходит :(

---
в файле MainWindow.cpp в этой строке:
Цитата
connect(allignRightAct, SIGNAL(triggered()), this, SLOT(AllignRigh()));

ошибка(жирное), должно быть AllignRight
Litkevich Yuriy Дата 22.3.2008, 14:04
  посмотри объявление:
QTextDocument * QTextEdit::document () const

метод document () возвращает тип = указатель на QTextDocument, затем ты к нему применяешь setAlignment(), а его в классе QTextDocument нет.
так что компиллер прав ;)
Alexey Дата 22.3.2008, 13:52
  это я пытался объявить в классе mdichild QTextEdit *textEdit и попытаться с помощью него выравнивание сделать и забыл убрать, там должно быть:

CODE
connect(document(), SIGNAL(contentsChanged()),
this, SLOT(documentWasModified()));
Просмотр темы полностью (откроется в новом окне)
RSS Текстовая версия Сейчас: 27.4.2024, 19:40