Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, December 2006
[Qt4.2] QAbstractItemView::setIndexWidget()


Message 1 in thread

Qt4.1 added QAbstractItemView::setIndexWidget(), but the 
documentation is a bit slim and I'm having a hard time
getting it to work (here's the docs:)

<http://doc.trolltech.com/4.1/qabstractitemview.html#setIndexWidget>

Is there documentation or discussion somewhere for how to use
QAbstractItemView::setIndexWidget()?  (I couldn't find anything
in the Qt docs or a Google search.)

I implement MyTableView (derived from QTableView) and want one
column to display formatted text.  I couldn't figure out how to do
that elegantly inside MyDelegate::paint() (e.g., you apparently can't
QPixmap::grabWidget(QLabel) inside a paint event), so I wanted to call
MyTableView::setIndexWidget() with a "QLabel" that displays
the formatted text.

I then overrode MyTableView::rowsInserted() to call "setIndexWidget()"
with a new QLabel on the added rows.  It very quickly "blinks" the 
formatted text, and then the view apparently uses the default 
MyDelegate::paint() to draw the cell where I set the index widget
(instead of relying on the widget I set for the cell).

I'd *hoped* the setIndexWidget() would cause the widget to display
the (read-only) interface for that cell.  Isn't that how it's supposed to
work?  Are there examples somewhere?

--charley





__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com

--
 [ signature omitted ] 

Message 2 in thread

<snip, how to use QAbstractItemView::setIndexWidget()>

Ok, I found a good thread in the archives talking about
trouble-shooting options with setIndexWidget():

<http://lists.trolltech.com/qt-interest/2006-02/thread00097-0.html>

I moved my setIndexWidget() to MyDelegate::paint() as
was done in the thread, and it works.  Kinda weird -- 
the docs should be updated to tell us where it's intended
that we place that call.

Now, I have another problem:  Because I setIndexWidget()
to get rich text rendering (works great), the user can no
longer trigger editing operations on that cell (i.e., 
MyItemDelegate::createEditor() never gets called for
that cell).  Apparently, the "edit" events are filtered out
because that cell has a read-only widget, and I can't
find an intercept to turn it back on.

I thought my goal/expectation was reasonable:

(1) Display (read-only) formatted text in the cell
(accomplished through setIndexWidget())

(2) Upon an edit event (e.g., double-click), createEditor()
to present a QTextEdit for the user to edit.

I can get *EITHER* to work, but not both at the same
time.  Huh?  Ideas?

Can I explicitly trigger an "edit" operation on that cell
(for example, if I "connect()" a double-click on the QLabel
in my setIndexWidget() to the "trigger-an-edit")?

BONUS QUESTION:

My "formatted text" is actually:

      "some text <u>_link_</u> some text"

...and, I'd like the link to apear like a hyper-link (e.g., 
I'd like to pop up a dialog if the user clicks on the underlined
"link text", as if it were a hyperlink).  Ideas on how to do this?

(This should conform to the "read-only" expectation of the
setIndexWidget(), and seems like a clean/elegant user
interface, so it seems like you should be able to do this...)

--charley









__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com

--
 [ signature omitted ] 

Message 3 in thread

On 23.12.06 16:56:52, Charley Bay wrote:
> Can I explicitly trigger an "edit" operation on that cell
> (for example, if I "connect()" a double-click on the QLabel
> in my setIndexWidget() to the "trigger-an-edit")?

Sure, there's a public slot on QAbstractItemView that is called "edit".
As for the double-click signal, I'd try QAbstractItemView::doubleClicked
;)

> My "formatted text" is actually:
> 
>       "some text <u>_link_</u> some text"
> 
> ...and, I'd like the link to apear like a hyper-link (e.g., 
> I'd like to pop up a dialog if the user clicks on the underlined
> "link text", as if it were a hyperlink).  Ideas on how to do this?

Use "<a href="something">linktext</a>" and connect a slot to the labels
linkActivated signal. Shouldn't be too hard.

Andreas

-- 
 [ signature omitted ] 

Message 4 in thread

Charley Bay wrote:
>> Can I explicitly trigger an "edit" operation on that cell
>> (for example, if I "connect()" a double-click on the QLabel
>> in my setIndexWidget() to the "trigger-an-edit")?


Andreas responded:
>Sure, there's a public slot on QAbstractItemView that is called "edit".
>As for the double-click signal, I'd try QAbstractItemView::doubleClicked
>;)


I saw the "edit", but then I'd have to do *all* the edit

work (I wanted to use the same pathway already

coded for createEditor()/setEditorData()/setModelData()).



Oh, wait -- I guess it's the same work.  Oops.  ;-)

(I'll try that.  ;-))


>> My "formatted text" is actually:
>> 
>>       "some text <u>_link_</u> some text"
>> 
>> ...and, I'd like the link to apear like a hyper-link (e.g., 
>> I'd like to pop up a dialog if the user clicks on the underlined
>> "link text", as if it were a hyperlink).  Ideas on how to do this?

>Use "<a href="something">linktext</a>" and connect a slot to the labels
>linkActivated signal. Shouldn't be too hard.


Ooops.  I *totally* missed <a href> was supported, and that

QLabel now has a "linkActivated()".



THANKS.


Ok, both my questions are user-error.  I'd better go to bed.

Thanks again!


--charley






__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com

--
 [ signature omitted ]