Qt-interest Archive, May 2008
Unable to get selection in QTextEdit.
Message 1 in thread
Hi,
I've written a small program to get selected text from a QTextEdit window
but I'm unable to get selection through it. On my system output of program
using this class says "Don't have selection", when I select some text in
text window and click getSelectButton.
#include <QTextEdit>
#include <QPushButton>
#include <QBoxLayout>
#include <QTextCursor>
#include <QTextDocument>
#include <QDebug>
class Main:public QWidget{
Q_OBJECT
QPushButton* getSelectButton;
QTextEdit* textEdit;
QTextCursor* textCursor;
public slots:
void getSelectSlot(){
qDebug()<<"getSelectSlot()";
QTextDocument* doc = textEdit->document();
textCursor = new QTextCursor(doc);
if(!textCursor->hasSelection())
qDebug()<<"Don't have selection";
}
public:
Main(QWidget* parent=0){
QVBoxLayout* vbox = new QVBoxLayout();
getSelectButton = new QPushButton("Get Selection!");
connect(getSelectButton,SIGNAL(clicked()),this,SLOT(getSelectSlot()));
textEdit = new QTextEdit();
vbox->addWidget(getSelectButton);
vbox->addWidget(textEdit);
setLayout(vbox);
}
};
--
[ signature omitted ]
Message 2 in thread
On Friday 23 May 2008 06.46:45 S Vashisht wrote:
> Hi,
>
> I've written a small program to get selected text from a QTextEdit window
> but I'm unable to get selection through it. On my system output of program
> using this class says "Don't have selection", when I select some text in
> text window and click getSelectButton.
>
> #include <QTextEdit>
> #include <QPushButton>
> #include <QBoxLayout>
> #include <QTextCursor>
> #include <QTextDocument>
> #include <QDebug>
>
> class Main:public QWidget{
> Q_OBJECT
>
> QPushButton* getSelectButton;
> QTextEdit* textEdit;
> QTextCursor* textCursor;
> public slots:
> void getSelectSlot(){
> qDebug()<<"getSelectSlot()";
> QTextDocument* doc = textEdit->document();
> textCursor = new QTextCursor(doc);
> if(!textCursor->hasSelection())
> qDebug()<<"Don't have selection";
> }
> public:
> Main(QWidget* parent=0){
> QVBoxLayout* vbox = new QVBoxLayout();
> getSelectButton = new QPushButton("Get
> Selection!");
> connect(getSelectButton,SIGNAL(clicked()),this,SLOT(getSelectSlot()));
> textEdit = new QTextEdit();
> vbox->addWidget(getSelectButton);
> vbox->addWidget(textEdit);
> setLayout(vbox);
> }
> };
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/
Hi,
For what you want to achieve, you should rather have something like this:
void getSelectSlot(){
qDebug()<<"getSelectSlot()";
/* there you get the cursor for your textEdit*/
QTextCursor cursor = textEdit->textCursor();
if(!cursor->hasSelection())
qDebug()<<"Don't have selection";
}
Cheers,
Samuel
--
[ signature omitted ]
Message 3 in thread
Hello,
I'm hoping this is simple, but I can't see to get it to work, I was to
customise the look of a custom QWidget I have made, but setting the CSS
doesn't seem to do anything. Here is some test code to illustrate the
problem
class CustomWidget : public QWidget
{
Q_OBJECT
public:
CustomWidget(QWidget *parent = 0);
};
class TestCSS : public QWidget
{
Q_OBJECT
public:
TestCSS(QWidget *parent = 0, Qt::WFlags flags = 0);
};
CustomWidget::CustomWidget(QWidget *parent)
: QWidget(parent)
{
setObjectName("CustomWidgetName");
QPushButton *button = new QPushButton("Inside CustomWidget", this);
QHBoxLayout *layout = new QHBoxLayout(this);
layout->addWidget(button);
}
TestCSS::TestCSS(QWidget *parent, Qt::WFlags flags)
: QWidget(parent, flags)
{
CustomWidget *customWidget = new CustomWidget(this);
QPushButton *button = new QPushButton("Inside TestCSS", this);
QHBoxLayout *mainLayout = new QHBoxLayout(this);
mainLayout->addWidget(customWidget);
mainLayout->addWidget(button);
setStyleSheet("QWidget#CustomWidgetName { background-color: Green; }");
}
This example is supposed to set the background of the widget behind the
button "Inside CustomWidget", but nothing happens, of course if i just
use "QWidget { background-color: Green; }" it will set the background
green, but on all the widgets, I just want that specific one to change.
I've read through:
http://doc.trolltech.com/4.4/stylesheet-syntax.html
but none of the selector types seem to work, perhaps someone can point
me in the right direction, I don't really want to have to reimplement
the paintEvent for each one, styling would be much easier.
Thanks,
Tim Edwards
--
[ signature omitted ]
Message 4 in thread
Hi,
> This example is supposed to set the background of the widget behind the
> button "Inside CustomWidget", but nothing happens, of course if i just
> use "QWidget { background-color: Green; }" it will set the background
> green, but on all the widgets, I just want that specific one to change.
Taking the Q_OBJECT macro away from CustomWidget lets the green background
to appear. Could somebody explain?
--
[ signature omitted ]