Results 1 to 7 of 7

Thread: setAlignment does not work again

  1. #1
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default setAlignment does not work again

    I am trying to align the text inside a QTextEdit.
    At bound the action menu to the setAlignment() slot of QTextEdit.
    But at runtime, besides the fact that no alignment takes place, I got the errors:

    Object::connect: No such slot QTextEdit::setAlignment(Qt::AlignRight)

    and so on.
    The signla/slot binding is:


    connect(act_alignright, SIGNAL(triggered(bool)), textEdit,SLOT(setAlignment(Qt::AlignRight)));

    Any reply will be very appreciated

  2. #2
    Join Date
    Oct 2007
    Location
    Cracow
    Posts
    56
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: setAlignment does not work again

    first of all it won't work because
    The signals and slots mechanism is type safe: The signature of a signal must match the signature of the receiving slot.
    so it's the reason why you get error

    http://doc.trolltech.com/4.4/signalsandslots.html

  3. #3
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setAlignment does not work again

    Don't understan:
    the slot setAlignement is a slot of textEdit and act_alignright is a signal of a menu.
    What am I missing?
    G

  4. #4
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setAlignment does not work again

    I solved. It seems the it's enough to call a callback from the connect function:

    connect(act_alignright, SIGNAL(triggered(bool)), this, SLOT(right()));
    connect(act_alignleft, SIGNAL(triggered(bool)), this, SLOT(left()));
    connect(act_aligncenter, SIGNAL(triggered(bool)), this, SLOT(center()));



    And then use setAlignment inside the callback.

  5. #5
    Join Date
    May 2008
    Posts
    15
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setAlignment does not work again

    Quote Originally Posted by giusepped View Post
    Don't understan:
    the slot setAlignement is a slot of textEdit and act_alignright is a signal of a menu.
    What am I missing?
    G
    Quote Originally Posted by giusepped View Post
    Qt Code:
    1. connect(act_alignright, SIGNAL(triggered(bool)), // <---this is bool
    2. textEdit,SLOT(setAlignment(Qt::AlignRight))); // <--this is not a bool, it is also a value and not a variable
    To copy to clipboard, switch view to plain text mode 
    You really need to read/understand: http://doc.trolltech.com/4.4/signalsandslots.html
    hope it helps

  6. #6
    Join Date
    Jun 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setAlignment does not work again

    I have problem with QTextEdit setAlignment()

    Qt Code:
    1. #ifndef TEDIT_H
    2. #define TEDIT_H
    3.  
    4. #include <QWidget>
    5.  
    6. class QToolBar;
    7. class QAction;
    8. class QTextEdit;
    9.  
    10. class TEdit : public QWidget
    11. {
    12. Q_OBJECT
    13. public:
    14. TEdit();
    15. virtual ~TEdit();
    16.  
    17. private slots:
    18. void makeBold();
    19. void makeItalic();
    20. void makeUnderline();
    21. void setAlignLeft();
    22. void setAlignCenter();
    23. void setAlignRight();
    24. private:
    25.  
    26. QToolBar *toolBar;
    27.  
    28. QAction *textBold;
    29. QAction *textItalic;
    30. QAction *textUnderline;
    31. QAction *textLeft;
    32. QAction *textCenter;
    33. QAction *textRight;
    34.  
    35. QTextEdit *te;
    36. };
    37.  
    38. #endif /* TEDIT_H_ */
    To copy to clipboard, switch view to plain text mode 
    implement
    Qt Code:
    1. #include <QtGui>
    2.  
    3. #include "tedit.h"
    4.  
    5. TEdit::TEdit()
    6. {
    7. resize(800,600);
    8. te = new QTextEdit;
    9. toolBar = new QToolBar(this);
    10.  
    11. textBold = new QAction(QIcon(":images/format_text_bold.png"),tr("B"),this);
    12. connect(textBold, SIGNAL(triggered()), this, SLOT(makeBold()));
    13. textItalic = new QAction(QIcon(":images/format_text_italic.png"),tr("I"),this);
    14. connect(textItalic, SIGNAL(triggered()), this, SLOT(makeItalic()));
    15. textUnderline = new QAction(QIcon(":images/format_text_underline.png"),tr("U"),this);
    16. connect(textUnderline, SIGNAL(triggered()), this, SLOT(makeUnderline()));
    17.  
    18. textLeft = new QAction(QIcon(":images/format_justify_left.png"),tr("Align Left"),this);
    19. connect(textLeft, SIGNAL(triggered()), this, SLOT(setAlignLeft()));
    20. textCenter = new QAction(QIcon(":images/format_justify_center.png"),tr("Align Center"),this);
    21. connect(textLeft, SIGNAL(triggered()), this, SLOT(setAlignCenter()));
    22. textRight = new QAction(QIcon(":images/format_justify_right.png"),tr("Align Right"),this);
    23. connect(textLeft, SIGNAL(triggered()), this, SLOT(setAlignRight()));
    24.  
    25. toolBar->addAction(textBold);
    26. toolBar->addAction(textItalic);
    27. toolBar->addAction(textUnderline);
    28. toolBar->addSeparator();
    29. toolBar->addAction(textLeft);
    30. toolBar->addAction(textCenter);
    31. toolBar->addAction(textRight);
    32.  
    33. ml->setMargin(1);
    34. ml->setSpacing(0);
    35. ml->addWidget(toolBar);
    36. ml->addWidget(te);
    37.  
    38. setLayout(ml);
    39. }
    40.  
    41. void TEdit::makeBold()
    42. {
    43. QTextCursor cursor = te->textCursor();
    44. QTextCharFormat boldFormat;
    45. if(cursor.charFormat().fontWeight()==QFont::Normal)
    46. {
    47. boldFormat.setFontWeight(QFont::Bold);
    48. }
    49. else
    50. {
    51. boldFormat.setFontWeight(QFont::Normal);
    52. }
    53.  
    54. cursor.mergeCharFormat(boldFormat);
    55.  
    56. }
    57.  
    58. void TEdit::makeItalic()
    59. {
    60. QTextCursor cursor = te->textCursor();
    61. QTextCharFormat italicFormat;
    62. if(cursor.charFormat().fontItalic()==false)
    63. {
    64. italicFormat.setFontItalic(true);
    65. }
    66. else
    67. {
    68. italicFormat.setFontItalic(false);
    69. }
    70. cursor.mergeCharFormat(italicFormat);
    71. }
    72.  
    73. void TEdit::makeUnderline()
    74. {
    75. QTextCursor cursor = te->textCursor();
    76. QTextCharFormat underlineFormat;
    77. if(cursor.charFormat().fontUnderline()==false)
    78. {
    79. underlineFormat.setFontUnderline(true);
    80. }
    81. else
    82. {
    83. underlineFormat.setFontUnderline(false);
    84. }
    85. cursor.mergeCharFormat(underlineFormat);
    86. }
    87.  
    88. void TEdit::setAlignLeft()
    89. {
    90. QTextCursor cursor = te->textCursor();
    91. QTextBlockFormat blockFmt;
    92. if(!cursor.hasSelection())
    93. {
    94. cursor.select(QTextCursor::BlockUnderCursor);
    95. }
    96. blockFmt.setAlignment(Qt::AlignLeft);
    97. cursor.mergeBlockFormat(blockFmt);
    98. }
    99. void TEdit::setAlignRight()
    100. {
    101. QTextCursor cursor = te->textCursor();
    102. QTextBlockFormat blockFmt;
    103. if(!cursor.hasSelection())
    104. {
    105. cursor.select(QTextCursor::BlockUnderCursor);
    106. }
    107. blockFmt.setAlignment(Qt::AlignRight);
    108. cursor.mergeBlockFormat(blockFmt);
    109. }
    110. void TEdit::setAlignCenter()
    111. {
    112. QTextCursor cursor = te->textCursor();
    113. QTextBlockFormat blockFmt;
    114. if(!cursor.hasSelection())
    115. {
    116. cursor.select(QTextCursor::BlockUnderCursor);
    117. }
    118. blockFmt.setAlignment(Qt::AlignCenter);
    119. cursor.mergeBlockFormat(blockFmt);
    120. }
    121. TEdit::~TEdit()
    122. {
    123. // TODO Auto-generated destructor stub
    124. }
    To copy to clipboard, switch view to plain text mode 
    compilation done, no errors or warnings

    but if i clicked on toolbar button to align left
    text align to right, and alignCenter, alignRight, alignLeft do nothing
    O_o

    also i try
    Qt Code:
    1. void TEdit::setAlignLeft()
    2. {
    3. te->setAlignment(Qt::AlignLeft);
    4. }
    To copy to clipboard, switch view to plain text mode 
    but not work
    Last edited by bugsstring; 7th October 2008 at 11:13.

  7. #7
    Join Date
    Jun 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setAlignment does not work again

    sorry problem fixed )))
    3 times textLeft )))

Similar Threads

  1. Printing via QPrinter doesnt work
    By mSergey in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2008, 19:00
  2. QActions don't work with menubar hidden
    By Pepe in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2007, 01:04
  3. Change work area OS
    By pakulo in forum Qt Programming
    Replies: 15
    Last Post: 15th May 2007, 07:20
  4. QTextEdit Justify align making work
    By dec0ding in forum Qt Programming
    Replies: 2
    Last Post: 13th January 2006, 12:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.