#pyqt | Logs for 2020-07-17
Back
[00:30:31] -!- kdas_ has joined #pyqt
[00:31:23] -!- kushal has quit [Ping timeout: 240 seconds]
[03:46:54] -!- sazawal has joined #pyqt
[03:56:40] -!- sazawal has quit [Quit: Leaving]
[03:57:01] -!- sazawal has joined #pyqt
[05:03:44] -!- jmarsac has joined #pyqt
[06:40:17] -!- cottoneyejim has joined #pyqt
[06:52:58] -!- cottoneyejim has quit [Ping timeout: 256 seconds]
[07:06:20] -!- jmarsac has quit [Ping timeout: 256 seconds]
[07:24:00] -!- jmarsac has joined #pyqt
[07:37:18] -!- BPL has joined #pyqt
[10:11:12] -!- BPL has quit [Quit: Leaving]
[11:46:35] -!- jmarsac has quit [Read error: Connection reset by peer]
[12:43:24] -!- honigkuchen has quit [Ping timeout: 256 seconds]
[12:58:15] -!- lemoldu has joined #pyqt
[14:03:22] -!- roussinm has joined #pyqt
[14:20:33] -!- cottoneyejim has joined #pyqt
[14:58:27] -!- jmarsac has joined #pyqt
[15:34:08] -!- bomex has joined #pyqt
[15:34:17] <bomex> hi
[15:35:06] <bomex> is there any way I can get a regular index of the items in a QTableWidget?
[15:35:44] <bomex> not QModelIndex, but the first item added as 0, the second item added as 1 ans so on...
[15:40:03] <bomex> I have 2 columns and, say 20 rows... how can I get the index number 11 if I click the 10th cell (starting from row 0 column 0) ??
[15:41:09] <bomex> oops, I mean index number 9 if I click the 10th cell
[15:41:48] <bomex> is that even possible?
[15:41:53] <altendky> bomex: you mean you are in some code triggered by the click and passed a QModelIndex and you want to know it is row 9 (zreo based)?
[15:42:10] <altendky> a QModelIndex has https://doc.qt.io
[15:43:16] <bomex> I am using the itemClicked piblic signal and my custom slot
[15:43:29] <bomex> public*
[15:44:15] <altendky> so itemClicked passes you a https://doc.qt.io which has a https://doc.qt.io method
[15:45:11] <bomex> yes, but I need the index of the item, not the row
[15:45:45] <altendky> bomex: what index? not the integer that is the index of the row?
[15:46:09] <bomex> well, the integer of the item
[15:46:12] <altendky> if the item clicked is in the first row then .row() will return 0
[15:46:29] <altendky> bomex: integer of the item? it takes two integers to describe an item, row and column
[15:46:45] <altendky> and there is also a column method https://doc.qt.io
[15:47:19] <bomex> but what is currentRow and currentColumn useful here?
[15:47:54] <altendky> bomex: i'm not following 'but'. did i not link you to what you needed?
[15:47:59] <bomex> what if the item is in the first row but second column?
[15:48:18] <altendky> bomex: then the row and column methods will give you the corresponding indexes
[15:48:49] <altendky> integer indexes, not model indexes
[15:48:59] <altendky> bomex: what are you going to do with these numbers?
[15:49:01] <bomex> sorry for the typo, I ment to ask: are currentRow and currentColumn useful for my needs?
[15:49:25] <altendky> bomex: i wouldn't use them given you were passed the item and it can tell you where it is.
[15:49:55] <bomex> these numbers are going to be used as indexes to a list
[15:50:01] -!- cottoneyejim has quit [Ping timeout: 264 seconds]
[15:50:10] <bomex> my_list[my_index]
[15:50:12] <bomex> like so
[15:50:47] <altendky> bomex: then just do .row() and .column() to get those two values. i'm not sure why you would want to ignore the thing passed to you and go look elsewhere for hopefully the proper value maybe.
[15:51:14] <bomex> I need just one number
[15:51:54] <altendky> bomex: you can get the row and you can get the column. do what you need with one, the other, or both... to get the one number you need.
[15:52:00] <bomex> so row 0 & column 0 should be index 0 (obviously)
[15:52:19] <altendky> presumably this all isn't obvious given we are still talking about it
[15:52:22] <bomex> then row 0 & column 1 should be index 1
[15:52:47] <bomex> row 1 & column 0 should be index 2
[15:53:12] <altendky> bomex: ok, write out a few more and figure out how to calculate the number you want from the other two numbers
[15:53:38] <bomex> please give me a hint
[15:54:20] <bomex> row 0, column 0 = index 0
[15:54:34] <bomex> row 0, column 1 = index 1
[15:54:49] <bomex> row 1, column 0 = index 2
[15:55:15] <bomex> row 1, column 1 = index 3
[15:55:58] <altendky> bomex: so increasing the column by one with the row staying the same has what effect on the resulting number you need?
[15:56:15] <altendky> and then after that, increasing the row by one with the same column value has what effect on the output?
[15:56:44] <bomex> I have no idea
[15:56:52] <altendky> look at your table
[15:56:57] <bomex> okay
[15:57:03] <bomex> looking
[15:58:01] <altendky> to answer the first let's first consider row=0. what is the difference in output from column=0 to column=1?
[15:59:07] <bomex> but when I click on an item in my table (the signal itemClicked is emitted), I must get that index, no matter which cell is clicked
[15:59:46] <altendky> bomex: ok, you can choose to not follow my suggestions and learn.
[16:00:20] <altendky> your 'but's are not really 'but's but more just not focusing on getting to the solution.
[16:00:29] <bomex> okay, row=0
[16:01:31] <bomex> but row 0 has two cells
[16:01:35] <altendky> yes
[16:01:58] <altendky> and i asked how the output index differed between column=0 and column=1 while row=0
[16:02:45] <altendky> we're looking to see what the relationship between the resulting index you want is vs. the column changing. then we'll do the same for row. then we'll know how to calculate the output index from the column and row
[16:02:47] <bomex> uhmm, the index I want to get will always be 0?
[16:03:12] <altendky> look back at your table. i'm pretty sure it won't be always zero since you wrote values of 0, 1, 2, and 3 for it
[16:03:28] <altendky> so presumably there's only one case where you want it to be 0
[16:03:34] <bomex> I didn't write anything yet
[16:03:46] <altendky> 15:54 <bomex> row 0, column 0 = index 0
[16:03:46] <altendky> 15:54 <bomex> row 0, column 1 = index 1
[16:03:46] <altendky> 15:54 <bomex> row 1, column 0 = index 2
[16:03:46] <altendky> 15:55 <bomex> row 1, column 1 = index 3
[16:03:51] <bomex> oh that
[16:03:55] <altendky> yes, your table...
[16:03:59] -!- cottoneyejim has joined #pyqt
[16:04:39] <bomex> that's just what I want to get as an index
[16:04:55] <altendky> yup
[16:05:06] <bomex> if I click, say, row 1 and column 1 I want to get index number 3
[16:05:11] <altendky> so you are given row and column and we need to figure out how to calculate the index you want from them
[16:05:16] <altendky> yup
[16:05:30] <bomex> yes
[16:05:41] <bomex> exactly
[16:05:52] <bomex> that's what I want (and need)
[16:05:53] <altendky> so you need to write a function `def calculate_index(row, column):`
[16:06:06] <altendky> and i am trying to lead you to knowing what goes in that function
[16:06:17] <bomex> ah, a function! okay, cool
[16:06:46] <bomex> one in-between question...
[16:07:07] <bomex> since I am using itemClicked signal, right?
[16:08:03] <altendky> so you have stated
[16:08:40] <bomex> and if in my slot I do my_table.rowCount ..... will I get the number of the current row it was clicked or the total number my table has?
[16:10:17] <altendky> why would something called "row count" give you something other than the count of the rows? and why do you keep ignoring the methods i linked to and instead keep looking for _anything_ else to use instead
[16:10:38] <bomex> I just wanna know
[16:10:43] <altendky> you were passed a thing, you want to know what row it is, it has a row method... why would you use anything else?
[16:10:58] <bomex> anyway, I need a function that is outside my slot
[16:11:01] <altendky> no, row count doesn't give something other than the count of the rows
[16:11:28] <altendky> or just an expression, whatever... this is literally two operations but you refuse to focus in the slightest. i'm close to moving on.
[16:11:28] <bomex> a total number of the rows that exist in the table
[16:11:33] <bomex> i understand
[16:12:25] <bomex> okay, we have now def calculate_index(row, column)
[16:12:37] <bomex> we need the body, the most important part
[16:13:04] <altendky> so, back to the table and my questions
[16:13:08] <altendky> 15:54 <bomex> row 0, column 0 = index 0
[16:13:08] <altendky> 15:54 <bomex> row 0, column 1 = index 1
[16:13:08] <altendky> 15:54 <bomex> row 1, column 0 = index 2
[16:13:08] <altendky> 15:55 <bomex> row 1, column 1 = index 3
[16:13:20] <altendky> first let us figure out what effect the column value has on the index
[16:13:27] <bomex> okay
[16:13:42] <altendky> so consider when row is 0. what happens to the index when the column changes from 0 to 1
[16:13:43] <altendky> ?
[16:13:58] <bomex> the row number stays the same
[16:14:04] <altendky> i didn't ask that
[16:14:08] <altendky> i stated that
[16:14:16] <altendky> "what happens to the index"
[16:14:18] <bomex> there was a question mark
[16:14:31] <altendky> yes, i asked something else...
[16:14:45] <bomex> the index... uhm, the index should increase by 1
[16:14:59] <altendky> ok. so the column increasing by one, in at least this case, increases the index by 1
[16:15:05] <altendky> now let us consider another case
[16:15:15] <bomex> okay
[16:15:23] <altendky> when row is 1... what happens to the index when the column changes from 0 to 1?
[16:16:00] <bomex> the index increases yet again by 1
[16:16:10] <altendky> sounds good
[16:16:16] <altendky> ok
[16:16:39] <altendky> now what about when column is 0? what happens to the index when the row changes from 0 to 1?
[16:17:33] <bomex> the index increases by 1
[16:17:54] <bomex> every cell has a unique integer
[16:18:00] <altendky> that's wrong
[16:18:24] <altendky> 15:54 <bomex> row 0, column 0 = index 0
[16:18:24] <altendky> 15:54 <bomex> row 1, column 0 = index 2
[16:18:40] <altendky> we are considering those two entries in the table. column is 0, row changes from 0 to 1
[16:18:47] <altendky> what happens to the index?
[16:18:59] <bomex> wait, let me think
[16:19:45] <altendky> it starts at 0 and changes to 2. it increases by <what>
[16:19:57] <bomex> 2?
[16:20:00] <altendky> yes
[16:20:25] <altendky> ok, now let's consider when column=1 and row changes from 0 to 1 so we can see a different case of row changing
[16:20:42] <altendky> 15:54 <bomex> row 0, column 1 = index 1
[16:20:42] <altendky> 15:55 <bomex> row 1, column 1 = index 3
[16:20:50] <altendky> what happens to the induex
[16:21:07] <bomex> it increases by 2
[16:21:15] <altendky> correct
[16:21:33] <altendky> ok. so increasing the column by one increases the index by one. increasing the row by one increases the column by two.
[16:22:07] <bomex> so it seems
[16:22:50] <altendky> index = (2 * row) + (1 * column)
[16:23:52] <altendky> first note that 1 in 1*column corresponds to increasing by one when the column increases by one
[16:24:05] <altendky> and the 2*row corresponds to increasing by two when the row increases by one
[16:24:42] <altendky> then also note that 2 is the number of columns you have. that is not coincidence. if you had three columns (i know it makes no sense here, but in some other case) then it would be 3*row
[16:24:49] <bomex> def calculate_index(row, column): index = (2 * row) + (1 * column)
[16:25:08] <altendky> so the general answer is (column_count * row_index) + column_index
[16:28:14] <bomex> okay so: column_count is retrieved by my_table.columnCount() yes?
[16:28:33] <altendky> sounds reasonable
[16:28:56] <bomex> what about row_index?
[16:29:09] <bomex> how can I retieve those?
[16:29:30] <bomex> retrieve it*
[16:29:33] <altendky> that's what i linked way above. the .row() and .column() methods on the thing passed to your slot
[16:31:22] <bomex> I didn't know PyQt passes anything with the signal
[16:31:52] <bomex> so itemClicked signal carries data what row and column was clicked?
[16:32:34] <bomex> I don't understand
[16:32:49] <altendky> https://doc.qt.io
[16:33:03] <altendky> https://doc.qt.io
[16:33:17] <altendky> https://www.riverbankcomputing.com
[16:33:29] <altendky> the answer is yes, but please do read all of those
[16:33:53] <altendky> the signal emits a https://doc.qt.io
[16:35:00] <bomex> yes, a QTableWidgetItem is emitted
[16:35:15] <altendky> and it has .row() and .column() methods
[16:35:28] <bomex> I see
[16:35:29] <altendky> that give you the indexes for the row and column accordingly
[16:35:43] <bomex> I didn't know that
[16:35:53] <bomex> thanks for telling me this
[16:35:57] <bomex> :)
[16:36:04] <altendky> sure thing
[16:36:51] <bomex> okay let me go and implement this
[16:43:32] <bomex> altendky 22:29:19
[16:43:57] <bomex> on the thing passed to my slot?
[16:44:11] <bomex> this part I don't fully understand
[16:44:28] <bomex> what thing? and what that is passed to my slot?
[16:45:45] <bomex> how can I refer to the thing that was passed to my slot?
[16:46:02] <altendky> bomex: did you read the doc links?
[16:46:24] <bomex> since I used itemClicked signal, I get the QTableWidgetItem passed
[16:46:49] <bomex> but how can I refer to this QTableWidgetItem?
[16:47:41] <bomex> in my slot
[16:48:15] <bomex> this is hard to grasp
[16:49:02] <altendky> 16:46 <altendky> bomex: did you read the doc links?
[16:49:56] <bomex> yes, I did
[16:50:04] <bomex> this is a part I don't understand
[16:51:19] <bomex> self.row() ?
[16:52:01] <bomex> I am not subclassing QTableWidgetItem to refer to it with self
[16:52:58] <bomex> please answer me this
[16:53:10] <bomex> I am not as smart as you might think
[16:54:29] <bomex> is it item ?
[16:54:38] <altendky> I find it hard to imagine the docs don't describe how to receive a value from a signal in a slot.
[16:54:44] <bomex> it's kinda hard to read C++ code
[16:54:53] <bomex> I know only Python
[16:55:39] <bomex> void QTableWidget::itemClicked(QTableWidgetItem *item)
[16:56:02] <bomex> *item ? is that a reference to QTableWidgetItem ?
[16:56:38] <bomex> the asterisk means a reference in C++?
[16:58:46] <bomex> hello???
[17:00:15] <bomex> why the fuck are you leaving me hanging here?
[17:00:22] <bomex> I just don't know!!!
[17:00:26] <bomex> tell me!!!
[17:01:27] <bomex> my_table.currentItem.row() ???
[17:01:33] <bomex> item.row() ???
[17:01:47] <bomex> my_table.item.row() ???
[17:01:55] <bomex> are you DEAD?!
[17:03:30] <bomex> you know what? !!! FUCK YOU !!!
[17:03:39] <bomex> ASSHOLE
[17:03:52] -!- bomex has quit [Remote host closed the connection]
[17:12:45] -!- kdas_ has quit [Remote host closed the connection]
[17:13:44] -!- kushal has joined #pyqt
[17:20:47] -!- sazawal has quit [Quit: Leaving]
[17:24:43] -!- enko- has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
[17:32:01] -!- lemoldu has quit [Ping timeout: 264 seconds]
[17:34:45] -!- lemoldu has joined #pyqt
[17:40:51] -!- lemoldu has quit [Quit: Leaving]
[17:42:31] <altendky> heh, finally got reconnected. but hey, we'll see if after two years from starting to poke at qt if they can figure out how to receive a value emitted from a slot...
[19:32:13] -!- roussinm has quit [Quit: WeeChat 2.3]
[20:34:30] -!- jmarsac has quit [Read error: Connection reset by peer]
[20:46:13] -!- cottoneyejim has quit [Ping timeout: 258 seconds]
[20:47:30] -!- honigkuchen has joined #pyqt
[22:51:52] -!- TechSmurf has quit [Quit: leaving]
[22:52:47] -!- TechSmurf has joined #pyqt
[22:53:59] -!- TechSmurf has quit [Client Quit]
[22:56:24] -!- TechSmurf has joined #pyqt
[22:57:35] -!- TechSmurf has quit [Client Quit]
[22:58:02] -!- TechSmurf has joined #pyqt
[23:31:50] -!- enko- has joined #pyqt